From 20029aec58b7167a3d82daa8f78406ebc18fc897 Mon Sep 17 00:00:00 2001 From: Drylozu <35281350+Drylozu@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:59:56 -0500 Subject: [PATCH] feat: show api route on request error --- src/api/api.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/api/api.ts b/src/api/api.ts index 17df6644..b91c1c02 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -167,7 +167,7 @@ export class ApiHandler { } } } - const parsedError = this.parseError(response, result); + const parsedError = this.parseError(route, response, result); this.debugger?.warn(parsedError); reject(parsedError); return; @@ -207,7 +207,7 @@ export class ApiHandler { }); } - parseError(response: Response, result: unknown) { + parseError(route: `/${string}`, response: Response, result: unknown) { let errMessage = ''; if (typeof result === 'object' && result) { if ('message' in result) { @@ -218,10 +218,8 @@ export class ApiHandler { errMessage += `${JSON.stringify(result.errors, null, 2)}\n`; } } - if (errMessage.length) { - return new Error(errMessage); - } - return new Error(response.statusText); + errMessage += ` at [${response.status} ${response.statusText}] ${route}`; + return new Error(errMessage); } async handle50X(method: HttpMethods, url: `/${string}`, request: ApiRequestOptions, next: () => void) {