Improve error handling in some cases
In Cyclone's fetchBare(), the content type wasn't correct, and the status line should be "Internal Server Error", not just "Error". In the main request handler, I added similar error handling, just in case.
This commit is contained in:
parent
4ec92aec50
commit
4ff19c9fa5
2 changed files with 15 additions and 8 deletions
19
app.js
19
app.js
|
|
@ -19,12 +19,19 @@ const serve = new nodeStatic.Server(join(
|
|||
const server = http.createServer();
|
||||
|
||||
server.on('request', (request, response) => {
|
||||
if (custombare.route(request, response)) return true;
|
||||
|
||||
if (bareServer.shouldRoute(request)) {
|
||||
bareServer.routeRequest(request, response);
|
||||
} else {
|
||||
serve.serve(request, response);
|
||||
try {
|
||||
if (custombare.route(request, response)) return true;
|
||||
|
||||
if (bareServer.shouldRoute(request)) {
|
||||
bareServer.routeRequest(request, response);
|
||||
} else {
|
||||
serve.serve(request, response);
|
||||
}
|
||||
} catch (e) {
|
||||
response.writeHead(500, "Internal Server Error", {
|
||||
"Content-Type": "text/plain"
|
||||
})
|
||||
response.end(e.stack)
|
||||
}
|
||||
});
|
||||
server.on('upgrade', (req, socket, head) => {
|
||||
|
|
|
|||
|
|
@ -82,8 +82,8 @@ async function fetchBare(url, res, req) {
|
|||
request.body.pipe(res)
|
||||
}
|
||||
} catch (e) {
|
||||
res.writeHead(500, 'Error', {
|
||||
'content-type': 'application/javascript'
|
||||
res.writeHead(500, 'Internal Server Error', {
|
||||
'Content-Type': 'text/plain'
|
||||
})
|
||||
res.end(e.stack);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue