Skip to content

Commit

Permalink
feat: show api route on request error
Browse files Browse the repository at this point in the history
  • Loading branch information
Drylozu committed Nov 4, 2024
1 parent db9e319 commit 20029ae
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 20029ae

Please sign in to comment.