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:
CountBleck 2022-08-30 15:24:48 -07:00
parent 4ec92aec50
commit 4ff19c9fa5
2 changed files with 15 additions and 8 deletions

19
app.js
View file

@ -19,12 +19,19 @@ const serve = new nodeStatic.Server(join(
const server = http.createServer(); const server = http.createServer();
server.on('request', (request, response) => { server.on('request', (request, response) => {
if (custombare.route(request, response)) return true; try {
if (custombare.route(request, response)) return true;
if (bareServer.shouldRoute(request)) {
bareServer.routeRequest(request, response); if (bareServer.shouldRoute(request)) {
} else { bareServer.routeRequest(request, response);
serve.serve(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) => { server.on('upgrade', (req, socket, head) => {

View file

@ -82,8 +82,8 @@ async function fetchBare(url, res, req) {
request.body.pipe(res) request.body.pipe(res)
} }
} catch (e) { } catch (e) {
res.writeHead(500, 'Error', { res.writeHead(500, 'Internal Server Error', {
'content-type': 'application/javascript' 'Content-Type': 'text/plain'
}) })
res.end(e.stack); res.end(e.stack);
} }