From 54b2db67007f4628e4e22616c70f06ca27d4e366 Mon Sep 17 00:00:00 2001 From: roushou Date: Thu, 27 Jun 2024 20:10:00 +0700 Subject: [PATCH] fix: make http requests throw when status not ok --- packages/utils/http.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/utils/http.ts b/packages/utils/http.ts index ca1e835..eb3f9af 100644 --- a/packages/utils/http.ts +++ b/packages/utils/http.ts @@ -14,6 +14,9 @@ export async function get( ...options?.headers, }, }); + if (!resp.ok) { + throw new Error(`GET: request to ${url} failed`); + } return (await resp.json()) as TResponse; } @@ -29,5 +32,8 @@ export async function post( ...options?.headers, }, }); + if (!resp.ok) { + throw new Error(`POST: request to ${url} failed`); + } return (await resp.json()) as TResponse; }