Skip to content

Commit ab27551

Browse files
committed
Change httpCall promise handling
1 parent ee9c3f1 commit ab27551

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/Utils.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ export function normalizeDomain(domain: string): string {
2525
}
2626

2727
export async function httpCall<JsonResponse>(url: string, init?: RequestInit): Promise<JsonResponse> {
28-
const response = await fetch(url, init);
29-
30-
if (response.status >= 200 && response.status <= 299) {
31-
return (await response.json()) as JsonResponse;
32-
}
33-
34-
throw new Error(response.statusText);
28+
return await fetch(url, init).then(async (response) => {
29+
if (response.status >= 200 && response.status <= 299) {
30+
return (await response.json()) as JsonResponse;
31+
}
32+
throw new Error(response.statusText);
33+
}).then((response) => {
34+
return response;
35+
}).catch((error) => {
36+
throw new Error(error);
37+
})
3538
}
3639

3740
export function addWindowEventListener(eventType: string, callback: any): () => void {

0 commit comments

Comments
 (0)