set correct content type for error messages

This commit is contained in:
zadam
2022-07-01 00:01:29 +02:00
parent fac9fef652
commit 3faae63b84
9 changed files with 71 additions and 27 deletions

View File

@@ -120,6 +120,10 @@ function apiResultHandler(req, res, result) {
function send(res, statusCode, response) {
if (typeof response === 'string') {
if (statusCode >= 400) {
res.setHeader("Content-Type", "text/plain");
}
res.status(statusCode).send(response);
return response.length;
@@ -167,7 +171,9 @@ function route(method, path, middleware, routeHandler, resultHandler, transactio
.catch(e => {
log.error(`${method} ${path} threw exception: ` + e.stack);
res.status(500).send(e.message);
res.setHeader("Content-Type", "text/plain")
.status(500)
.send(e.message);
});
}
else {
@@ -180,7 +186,9 @@ function route(method, path, middleware, routeHandler, resultHandler, transactio
catch (e) {
log.error(`${method} ${path} threw exception: ` + e.stack);
res.status(500).send(e.message);
res.setHeader("Content-Type", "text/plain")
.status(500)
.send(e.message);
}
});
}