Added restifyError handler

This commit is contained in:
Andris Reinman 2022-11-24 13:21:10 +02:00
parent e27eea14ff
commit 4686b81875
No known key found for this signature in database
GPG key ID: DC6C83F4D584D364
4 changed files with 19 additions and 3 deletions

9
api.js
View file

@ -565,10 +565,17 @@ module.exports = done => {
started = true;
return done(err);
}
log.error('API', err);
});
server.on('restifyError', (req, res, err, callback) => {
if (!started) {
started = true;
return done(err);
}
return callback();
});
server.listen(config.api.port, config.api.host, () => {
if (started) {
return server.close();

View file

@ -282,6 +282,7 @@ module.exports = (db, server) => {
code: 'AliasNotFound'
});
}
return res.json({
success: true,
id: aliasData._id.toString()

View file

@ -1102,7 +1102,15 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
//ignore
}
});
response.value.pipe(res);
return new Promise((resolve, reject) => {
response.value.pipe(res, { end: false });
response.value.on('end', () => {
res.end();
resolve();
});
response.value.on('error', err => reject(err));
});
})
);

View file

@ -644,7 +644,7 @@ module.exports = {
responseWrapper: middleware => async (req, res) => {
try {
await middleware(req, res, () => false);
await middleware(req, res);
} catch (err) {
let data = {
error: err.formattedMessage || err.message