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.
1 parent e1ed462 commit 52d3e63Copy full SHA for 52d3e63
src/index.js
@@ -44,15 +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);
+ res.setHeader('Content-Type', 'application/json');
+ res.statusCode = err.status || err.statusCode || 500;
49
+ res.end(JSON.stringify({ error: err.message }));
50
return;
51
}
52
if (!res.finished) {
53
if (!res.headersSent) {
- res.writeHead(404);
54
+ res.statusCode = 404;
55
- res.end(`'${req.url}' not found`);
56
+ res.end(JSON.stringify({ error: `'${req.url}' not found` }));
57
58
});
59
};
0 commit comments