feat: show API route on request error (#288)

This commit is contained in:
David 2024-11-04 18:13:38 -05:00 committed by GitHub
parent db9e319545
commit 15dd80a322
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -167,7 +167,7 @@ export class ApiHandler {
} }
} }
} }
const parsedError = this.parseError(response, result); const parsedError = this.parseError(route, response, result);
this.debugger?.warn(parsedError); this.debugger?.warn(parsedError);
reject(parsedError); reject(parsedError);
return; return;
@ -207,7 +207,7 @@ export class ApiHandler {
}); });
} }
parseError(response: Response, result: unknown) { parseError(route: `/${string}`, response: Response, result: unknown) {
let errMessage = ''; let errMessage = '';
if (typeof result === 'object' && result) { if (typeof result === 'object' && result) {
if ('message' in result) { if ('message' in result) {
@ -218,11 +218,9 @@ export class ApiHandler {
errMessage += `${JSON.stringify(result.errors, null, 2)}\n`; errMessage += `${JSON.stringify(result.errors, null, 2)}\n`;
} }
} }
if (errMessage.length) { errMessage += ` at [${response.status} ${response.statusText}] ${route}`;
return new Error(errMessage); return new Error(errMessage);
} }
return new Error(response.statusText);
}
async handle50X(method: HttpMethods, url: `/${string}`, request: ApiRequestOptions, next: () => void) { async handle50X(method: HttpMethods, url: `/${string}`, request: ApiRequestOptions, next: () => void) {
const wait = Math.floor(Math.random() * 1900 + 100); const wait = Math.floor(Math.random() * 1900 + 100);