From ceb6a2b630ee8826a4c471f0e9213ff99502f76e Mon Sep 17 00:00:00 2001 From: Federico Minaya Date: Tue, 27 Jun 2023 21:21:16 -0300 Subject: [PATCH] fix: throw error on sign up client side --- src/client.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index f9951e2..33a275e 100644 --- a/src/client.ts +++ b/src/client.ts @@ -12,10 +12,20 @@ export const signUp = async (payload: SignUpPayload): Promise => { method: 'POST', body: JSON.stringify(payload), headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json; charset=UTF-8' } }); + if (!res.ok) { + const isJson = res.headers + .get('Content-Type') + ?.includes('application/json'); + + const data = isJson ? await res.json() : await res.text(); + + throw new Error(data); + } + const user = await res.json(); return user;