Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make OAuthError extend GenericError #638

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions __mocks__/@auth0/auth0-spa-js.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ export const Auth0Client = jest.fn(() => {
logout,
};
});

export class GenericError extends Error {
constructor(public error: string, public error_description: string) {
super(error_description);
Object.setPrototypeOf(this, GenericError.prototype);
}
}
8 changes: 5 additions & 3 deletions src/errors.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { GenericError } from "@auth0/auth0-spa-js";

/**
* An OAuth2 error will come from the authorization server and will have at least an `error` property which will
* be the error code. And possibly an `error_description` property
*
* See: https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.3.1.2.6
*/
export class OAuthError extends Error {
constructor(public error: string, public error_description?: string) {
super(error_description || error);
export class OAuthError extends GenericError {
constructor(error: string, error_description?: string) {
super(error, error_description || error);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second argument is passed to the Error constructor, so I ensured it's identical as before.


// https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
Object.setPrototypeOf(this, OAuthError.prototype);
Expand Down