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);
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) {