From 964070dc4e9930df1b7c42f1ba8106de3d3accdd Mon Sep 17 00:00:00 2001 From: Thomas Poignant Date: Fri, 1 Aug 2025 14:18:50 +0200 Subject: [PATCH 1/2] feat(ofrep): adding error details for 401, 403 and 429 Signed-off-by: Thomas Poignant --- libs/shared/ofrep-core/src/lib/api/ofrep-api.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/shared/ofrep-core/src/lib/api/ofrep-api.ts b/libs/shared/ofrep-core/src/lib/api/ofrep-api.ts index d008d88f6..01b3c00e0 100644 --- a/libs/shared/ofrep-core/src/lib/api/ofrep-api.ts +++ b/libs/shared/ofrep-core/src/lib/api/ofrep-api.ts @@ -84,15 +84,15 @@ export class OFREPApi { } if (response.status === 401) { - throw new OFREPApiUnauthorizedError(response); + throw new OFREPApiUnauthorizedError(response, 'OFREP request failed: unauthorized'); } if (response.status === 403) { - throw new OFREPForbiddenError(response); + throw new OFREPForbiddenError(response, 'OFREP request failed: forbidden'); } if (response.status === 429) { - throw new OFREPApiTooManyRequestsError(response); + throw new OFREPApiTooManyRequestsError(response, 'OFREP request failed: too many requests'); } if (response.status === 200 && !this.isJsonMime(response)) { From c2fc41396e978e70965b723ca8b1421072df1a88 Mon Sep 17 00:00:00 2001 From: Thomas Poignant Date: Tue, 5 Aug 2025 11:43:00 +0200 Subject: [PATCH 2/2] move error into the exception itself Signed-off-by: Thomas Poignant --- libs/shared/ofrep-core/src/lib/api/errors.ts | 2 ++ libs/shared/ofrep-core/src/lib/api/ofrep-api.ts | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libs/shared/ofrep-core/src/lib/api/errors.ts b/libs/shared/ofrep-core/src/lib/api/errors.ts index 08c1f8900..a6b84f373 100644 --- a/libs/shared/ofrep-core/src/lib/api/errors.ts +++ b/libs/shared/ofrep-core/src/lib/api/errors.ts @@ -32,6 +32,7 @@ export class OFREPApiUnauthorizedError extends OFREPApiError { super(undefined, response, message, options); Object.setPrototypeOf(this, OFREPApiUnauthorizedError.prototype); this.name = OFREPApiUnauthorizedError.name; + this.message = message ?? 'OFREP request failed: unauthorized'; } } @@ -40,6 +41,7 @@ export class OFREPForbiddenError extends OFREPApiError { super(undefined, response, message, options); Object.setPrototypeOf(this, OFREPForbiddenError.prototype); this.name = OFREPForbiddenError.name; + this.message = message ?? 'OFREP request failed: forbidden'; } } diff --git a/libs/shared/ofrep-core/src/lib/api/ofrep-api.ts b/libs/shared/ofrep-core/src/lib/api/ofrep-api.ts index 01b3c00e0..d008d88f6 100644 --- a/libs/shared/ofrep-core/src/lib/api/ofrep-api.ts +++ b/libs/shared/ofrep-core/src/lib/api/ofrep-api.ts @@ -84,15 +84,15 @@ export class OFREPApi { } if (response.status === 401) { - throw new OFREPApiUnauthorizedError(response, 'OFREP request failed: unauthorized'); + throw new OFREPApiUnauthorizedError(response); } if (response.status === 403) { - throw new OFREPForbiddenError(response, 'OFREP request failed: forbidden'); + throw new OFREPForbiddenError(response); } if (response.status === 429) { - throw new OFREPApiTooManyRequestsError(response, 'OFREP request failed: too many requests'); + throw new OFREPApiTooManyRequestsError(response); } if (response.status === 200 && !this.isJsonMime(response)) {