Return correct content-type and HTTP code for errors
parent
b4e0ebd600
commit
2e89aa8b17
|
@ -122,6 +122,7 @@ class AntiEtcd
|
|||
data = Buffer.concat(data);
|
||||
let body = '';
|
||||
let code = 200;
|
||||
let ctype = 'text/plain; charset=utf-8';
|
||||
let reply;
|
||||
try
|
||||
{
|
||||
|
@ -144,6 +145,7 @@ class AntiEtcd
|
|||
}
|
||||
reply = await this.runHandler(req, data, res);
|
||||
reply = JSON.stringify(reply);
|
||||
ctype = 'application/json';
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
|
@ -169,8 +171,8 @@ class AntiEtcd
|
|||
'\n '+reply.replace(/\n/g, '\\n')
|
||||
);
|
||||
reply = Buffer.from(reply);
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json',
|
||||
res.writeHead(code, {
|
||||
'Content-Type': ctype,
|
||||
'Content-Length': reply.length,
|
||||
});
|
||||
res.write(reply);
|
||||
|
|
Loading…
Reference in New Issue