Skip to content

Commit d891175

Browse files
committed
Handle errors in 200 OK
1 parent 2f95a56 commit d891175

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/core/client.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,18 @@ async function post<T>(
5151
errors: json.errors || {},
5252
};
5353
}
54-
return <T>(await response.json()).data;
54+
// we still need to check for error as the API can return 200 with errors
55+
const json = await response.json();
56+
if (json.errors) {
57+
throw {
58+
code: 400,
59+
statusText: 'Error was returned from the API',
60+
message: json.errors[0].message,
61+
errors: json.errors || {},
62+
};
63+
}
64+
65+
return <T>json.data;
5566
} catch (exception) {
5667
throw exception;
5768
}

0 commit comments

Comments
 (0)