From 922e277553fb0108ca52a48976e5686729d3242c Mon Sep 17 00:00:00 2001 From: Federico Minaya Date: Tue, 27 Jun 2023 17:28:17 -0700 Subject: [PATCH 1/2] fix: throw error on sign up client side (#44) --- 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; From cdf5b93f8a2107ad4c76b43c1a3c4757fb939bfa Mon Sep 17 00:00:00 2001 From: Federico Minaya Date: Tue, 27 Jun 2023 17:28:31 -0700 Subject: [PATCH 2/2] fix: send response object in edge (#45) --- src/credentials.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/credentials.ts b/src/credentials.ts index 07fdbc1..9daddda 100644 --- a/src/credentials.ts +++ b/src/credentials.ts @@ -20,7 +20,18 @@ export const signUpHandler = }); if (user) { - res.json({ error: 'User already exist' }); + const response = { error: 'User already exist' }; + + if (isEdge) { + return new Response(JSON.stringify(response), { + headers: { + 'Content-Type': 'application/json' + }, + status: 400 + }); + } + + res.json(response); return; }