-
Notifications
You must be signed in to change notification settings - Fork 35
Open
Description
almost every API function has this code:
if (res.ok) {
const data = await res.json();
// ... other code ...
}the problem is that if this is called on a response from a route that has an OK response that returns a string and not json, like:
return res.status(OK).send("Card successfully verified");an error will be thrown because the response body doesn't have json to parse. that means that errors will be thrown when the behavior was actually correct. so we can do one of two things:
either we
- have API functions check the type of the response body:
let data;
const contentType = response.headers.get('content-type');
if (contentType?.includes('application/json')) {
data = await response.json();
} else {
data = await response.text();
}OR we
- refactor the routes' OK responses to just return these strings in a json format, like:
return res.status(OK).json({
message: "Card successfully verified"
});Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels