Skip to content

Commit 4cd12bc

Browse files
Update index.js
1 parent 4f9f093 commit 4cd12bc

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,17 @@ const handler = (req, res) => {
4545
// eslint-disable-next-line no-console
4646
console.error(err);
4747
res.statusCode = err.status || err.statusCode || 500;
48-
res.setHeader('Content-Type', 'application/json');
48+
if (!res.headersSent) {
49+
res.setHeader('Content-Type', 'application/json');
50+
}
4951
res.end(JSON.stringify({ errors: [{message: err.message}] }));
5052
return;
5153
}
5254
if (!res.finished) {
5355
if (!res.headersSent) {
5456
res.statusCode = 404;
5557
}
56-
res.setHeader('Content-Type', 'application/json');
57-
res.end(JSON.stringify({ error: `'${req.url}' not found` }));
58+
res.end(`'${req.url}' not found`);
5859
}
5960
});
6061
};

0 commit comments

Comments
 (0)