Skip to content

Commit 9cea079

Browse files
committed
Add error handling for failed fetch requests
1 parent ddce9ed commit 9cea079

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

api/src/fetch/service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export class FetchService {
4848
private async fetch<T>(url: string, options: FetchOptions) {
4949
this.logger.info({ message: `Fetching ${url}` });
5050
const response = await this.makeFetchHappenInstance(url, options);
51+
if (!response.ok) {
52+
this.logger.error({ message: `Failed to fetch ${url}`, meta: { status: response.status } });
53+
throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
54+
}
5155
const jsonResponse = (await response.json()) as T;
5256
return jsonResponse;
5357
}

0 commit comments

Comments
 (0)