Skip to content

Commit

Permalink
fix: throw error on sign up client side (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
fedeya authored Jun 28, 2023
1 parent fba852d commit 922e277
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@ export const signUp = async (payload: SignUpPayload): Promise<User> => {
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;
Expand Down

0 comments on commit 922e277

Please sign in to comment.