mirror of
https://github.com/nodemailer/wildduck.git
synced 2024-12-26 18:01:01 +08:00
Added restifyError handler
This commit is contained in:
parent
e27eea14ff
commit
4686b81875
4 changed files with 19 additions and 3 deletions
9
api.js
9
api.js
|
@ -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();
|
||||
|
|
|
@ -282,6 +282,7 @@ module.exports = (db, server) => {
|
|||
code: 'AliasNotFound'
|
||||
});
|
||||
}
|
||||
|
||||
return res.json({
|
||||
success: true,
|
||||
id: aliasData._id.toString()
|
||||
|
|
|
@ -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));
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue