Skip to content

Commit

Permalink
fix: make http requests throw when status not ok
Browse files Browse the repository at this point in the history
  • Loading branch information
roushou committed Jun 27, 2024
1 parent 56c023c commit 54b2db6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/utils/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export async function get<TResponse>(
...options?.headers,
},
});
if (!resp.ok) {
throw new Error(`GET: request to ${url} failed`);
}
return (await resp.json()) as TResponse;
}

Expand All @@ -29,5 +32,8 @@ export async function post<TResponse>(
...options?.headers,
},
});
if (!resp.ok) {
throw new Error(`POST: request to ${url} failed`);
}
return (await resp.json()) as TResponse;
}

0 comments on commit 54b2db6

Please sign in to comment.