sendgrid-nodejs icon indicating copy to clipboard operation
sendgrid-nodejs copied to clipboard

Returning empty response body causes unexpected errors

Open jfbrennan opened this issue 1 year ago • 0 comments

The Mail Send v3 API supports JSON, but on a successful request the response body comes back empty, which is bad practice for JSON endpoints. What happens is:

const json = await response.json(); // <--- "SyntaxError: Unexpected end of JSON input"

JSON endpoints should, at a minimum, return a JSON-compatible response, even an empty string would prevent this unexpected error. See https://developer.mozilla.org/en-US/docs/Web/API/Response/json#return_value

jfbrennan avatar Nov 27 '24 04:11 jfbrennan