From 6280b96965a744ff29a645ea10b72d0ff7790dce Mon Sep 17 00:00:00 2001 From: Henrique Serro Date: Wed, 27 Oct 2021 11:36:26 +0200 Subject: [PATCH] Improved error codes/messages consistency --- src/Logger.ts | 2 +- src/Oauth.ts | 2 +- src/Popup.ts | 4 ++-- src/Utils.ts | 4 ++-- src/index.ts | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Logger.ts b/src/Logger.ts index 47a5eeb..4c739d8 100644 --- a/src/Logger.ts +++ b/src/Logger.ts @@ -21,7 +21,7 @@ export function logMessage(type: string, info: LogInfo): void { break; case 'error': if (!disabledLogs.errors) { - console.error(`%c${info.code}:%c ${info.message}`, info.error || ''); + console.error(`${info.code}: ${info.message}`, info.error || ''); } break; default: diff --git a/src/Oauth.ts b/src/Oauth.ts index 3bcc62b..9dc6344 100644 --- a/src/Oauth.ts +++ b/src/Oauth.ts @@ -74,7 +74,7 @@ export async function initializeOauthSession(domain: string): Promise { return session?.data.key; } catch { - throw new AuthenticatorError('ERR_SESSION', 'Error generating session.'); + throw new AuthenticatorError('ERR_AUTH_SESSION', 'Error generating session.'); } } diff --git a/src/Popup.ts b/src/Popup.ts index badf849..a425b38 100644 --- a/src/Popup.ts +++ b/src/Popup.ts @@ -88,7 +88,7 @@ export class Popup { ); if (!popUp) { - throw new AuthenticatorError('ERR_POPUP_BLOCKED', 'Popup is blocked. Make sure to enable popups.'); + throw new AuthenticatorError('ERR_AUTH_POPUP_BLOCKED', 'Popup is blocked. Make sure to enable popups.'); } return popUp; @@ -139,6 +139,6 @@ export class Popup { return; } - throw new AuthenticatorError('ERR_POPUP_CLOSED', 'Popup is closed.'); + throw new AuthenticatorError('ERR_AUTH_POPUP_CLOSED', 'Popup is closed.'); } } diff --git a/src/Utils.ts b/src/Utils.ts index 6311fe6..9856cd6 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -32,7 +32,7 @@ export async function httpCall(url: string, init?: RequestInit): P if (response.status >= 200 && response.status <= 299) { return (await response.json()) as JsonResponse; } - throw new AuthenticatorError('ERR_HTTP_REQUEST', response.statusText); + throw new AuthenticatorError('ERR_AUTH_HTTP_REQUEST', response.statusText); }) .then((response: JsonResponse): JsonResponse => { return response; @@ -42,7 +42,7 @@ export async function httpCall(url: string, init?: RequestInit): P throw error; } - throw new AuthenticatorError('ERR_HTTP_REQUEST', error); + throw new AuthenticatorError('ERR_AUTH_HTTP_REQUEST', error); }); } diff --git a/src/index.ts b/src/index.ts index 1897b20..9ae4929 100644 --- a/src/index.ts +++ b/src/index.ts @@ -58,7 +58,7 @@ export async function authorize( }) .catch((error) => { if (error === false) { - throw new AuthenticatorError('ERR_DOMAIN_POPUP_CLOSED', 'Domain cancelled by client.'); + throw new AuthenticatorError('ERR_AUTH_DOMAIN_POPUP_CLOSED', 'Domain cancelled by client.'); } throw new AuthenticatorError('ERR_AUTH_FAILED', 'Auth failed.');