diff --git a/packages/profile-sync-controller/src/controllers/authentication/services.ts b/packages/profile-sync-controller/src/controllers/authentication/services.ts index 4fe49549962..b4225b8aeeb 100644 --- a/packages/profile-sync-controller/src/controllers/authentication/services.ts +++ b/packages/profile-sync-controller/src/controllers/authentication/services.ts @@ -1,3 +1,5 @@ +import log from 'loglevel'; + import { Env, Platform, getEnvUrls, getOidcClientId } from '../../shared/env'; const ENV_URLS = getEnvUrls(Env.PRD); @@ -37,13 +39,16 @@ export async function getNonce(publicKey: string): Promise { try { const nonceResponse = await fetch(nonceUrl.toString()); if (!nonceResponse.ok) { + log.error( + `authentication-controller/services: unable to get nonce - HTTP ${nonceResponse.status}`, + ); return null; } const nonceJson: NonceResponse = await nonceResponse.json(); return nonceJson?.nonce ?? null; } catch (e) { - console.error('authentication-controller/services: unable to get nonce', e); + log.error('authentication-controller/services: unable to get nonce', e); return null; } } @@ -107,13 +112,16 @@ export async function login( }); if (!response.ok) { + log.error( + `authentication-controller/services: unable to login - HTTP ${response.status}`, + ); return null; } const loginResponse: LoginResponse = await response.json(); return loginResponse ?? null; } catch (e) { - console.error('authentication-controller/services: unable to login', e); + log.error('authentication-controller/services: unable to login', e); return null; } } @@ -157,13 +165,16 @@ export async function getAccessToken( }); if (!response.ok) { + log.error( + `authentication-controller/services: unable to get access token - HTTP ${response.status}`, + ); return null; } const accessTokenResponse: OAuthTokenResponse = await response.json(); return accessTokenResponse?.access_token ?? null; } catch (e) { - console.error( + log.error( 'authentication-controller/services: unable to get access token', e, ); diff --git a/packages/profile-sync-controller/src/controllers/user-storage/services.ts b/packages/profile-sync-controller/src/controllers/user-storage/services.ts index 04032396c2b..1ccf1fd10cb 100644 --- a/packages/profile-sync-controller/src/controllers/user-storage/services.ts +++ b/packages/profile-sync-controller/src/controllers/user-storage/services.ts @@ -76,7 +76,9 @@ export async function getUserStorage( } if (userStorageResponse.status !== 200) { - throw new Error('Unable to get User Storage'); + throw new Error( + `Unable to get User Storage - HTTP ${userStorageResponse.status}`, + ); } const userStorage: GetUserStorageResponse | null = @@ -133,7 +135,9 @@ export async function getUserStorageAllFeatureEntries( } if (userStorageResponse.status !== 200) { - throw new Error('Unable to get User Storage'); + throw new Error( + `Unable to get User Storage - HTTP ${userStorageResponse.status}`, + ); } const userStorage: GetUserStorageAllFeatureEntriesResponse | null = @@ -222,7 +226,9 @@ export async function upsertUserStorage( }); if (!res.ok) { - throw new Error('user-storage - unable to upsert data'); + throw new Error( + `user-storage - unable to upsert data - HTTP ${res.status}`, + ); } } @@ -266,7 +272,9 @@ export async function batchUpsertUserStorage( }); if (!res.ok) { - throw new Error('user-storage - unable to batch upsert data'); + throw new Error( + `user-storage - unable to batch upsert data - HTTP ${res.status}`, + ); } } @@ -301,7 +309,9 @@ export async function batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries }); if (!res.ok) { - throw new Error('user-storage - unable to batch upsert data'); + throw new Error( + `user-storage - unable to batch upsert data - HTTP ${res.status}`, + ); } } @@ -326,11 +336,15 @@ export async function deleteUserStorage( }); if (userStorageResponse.status === 404) { - throw new Error('user-storage - feature/entry not found'); + throw new Error( + `user-storage - feature/entry not found - HTTP ${userStorageResponse.status}`, + ); } if (!userStorageResponse.ok) { - throw new Error('user-storage - unable to delete data'); + throw new Error( + `user-storage - unable to delete data - HTTP ${userStorageResponse.status}`, + ); } } @@ -370,7 +384,9 @@ export async function batchDeleteUserStorage( }); if (!res.ok) { - throw new Error('user-storage - unable to batch delete data'); + throw new Error( + `user-storage - unable to batch delete data - HTTP ${res.status}`, + ); } } @@ -394,10 +410,14 @@ export async function deleteUserStorageAllFeatureEntries( }); if (userStorageResponse.status === 404) { - throw new Error('user-storage - feature not found'); + throw new Error( + `user-storage - feature not found - HTTP ${userStorageResponse.status}`, + ); } if (!userStorageResponse.ok) { - throw new Error('user-storage - unable to delete data'); + throw new Error( + `user-storage - unable to delete data - HTTP ${userStorageResponse.status}`, + ); } }