We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents e1ed462 + 92d9356 commit b80865aCopy full SHA for b80865a
src/index.js
@@ -44,13 +44,16 @@ const handler = (req, res) => {
44
if (err) {
45
// eslint-disable-next-line no-console
46
console.error(err);
47
- res.writeHead(err.status || err.statusCode || 500);
48
- res.end(err.message);
+ if (!res.headersSent) {
+ res.statusCode = err.status || err.statusCode || 500;
49
+ res.setHeader('Content-Type', 'application/json');
50
+ }
51
+ res.end(JSON.stringify({ errors: [{message: err.message}] }));
52
return;
53
}
54
if (!res.finished) {
55
if (!res.headersSent) {
- res.writeHead(404);
56
+ res.statusCode = 404;
57
58
res.end(`'${req.url}' not found`);
59
0 commit comments