From 54ecb55742733ab5f6c54823ef44a93b2534fb8e Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Tue, 31 Oct 2023 09:42:38 +0100 Subject: [PATCH 1/3] Make OAuthError extend GenericError --- src/errors.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/errors.tsx b/src/errors.tsx index fc8a62d7..67380ab7 100644 --- a/src/errors.tsx +++ b/src/errors.tsx @@ -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(public error: string, public error_description: string = '') { + super(error, error_description || error); // 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); From 93599fe6416066a6462760577a85269de1cc8406 Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Tue, 31 Oct 2023 09:56:35 +0100 Subject: [PATCH 2/3] fix tests --- __mocks__/@auth0/auth0-spa-js.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/__mocks__/@auth0/auth0-spa-js.tsx b/__mocks__/@auth0/auth0-spa-js.tsx index b19548ad..735cd52a 100644 --- a/__mocks__/@auth0/auth0-spa-js.tsx +++ b/__mocks__/@auth0/auth0-spa-js.tsx @@ -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); + } +} From ce016d4ae3955198521726cb8f9f934cf3707ede Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Tue, 31 Oct 2023 10:28:40 +0100 Subject: [PATCH 3/3] Update src/errors.tsx Co-authored-by: Adam Mcgrath Signed-off-by: Frederik Prijck --- src/errors.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/errors.tsx b/src/errors.tsx index 67380ab7..e9dcf22d 100644 --- a/src/errors.tsx +++ b/src/errors.tsx @@ -7,7 +7,7 @@ import { GenericError } from "@auth0/auth0-spa-js"; * See: https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.3.1.2.6 */ export class OAuthError extends GenericError { - constructor(public error: string, public error_description: string = '') { + constructor(error: string, error_description?: string) { super(error, error_description || error); // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work