Skip to content

Commit

Permalink
Improved error codes/messages consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
henser committed Oct 27, 2021
1 parent f3fe773 commit 6280b96
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/Oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export async function initializeOauthSession(domain: string): Promise<string> {

return session?.data.key;
} catch {
throw new AuthenticatorError('ERR_SESSION', 'Error generating session.');
throw new AuthenticatorError('ERR_AUTH_SESSION', 'Error generating session.');
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.');
}
}
4 changes: 2 additions & 2 deletions src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function httpCall<JsonResponse>(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;
Expand All @@ -42,7 +42,7 @@ export async function httpCall<JsonResponse>(url: string, init?: RequestInit): P
throw error;
}

throw new AuthenticatorError('ERR_HTTP_REQUEST', error);
throw new AuthenticatorError('ERR_AUTH_HTTP_REQUEST', error);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down

0 comments on commit 6280b96

Please sign in to comment.