diff --git a/api.js b/api.js index 03eec82d..f0c3c222 100644 --- a/api.js +++ b/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(); diff --git a/lib/api/domainaliases.js b/lib/api/domainaliases.js index ad448f8d..2b6946ef 100644 --- a/lib/api/domainaliases.js +++ b/lib/api/domainaliases.js @@ -282,6 +282,7 @@ module.exports = (db, server) => { code: 'AliasNotFound' }); } + return res.json({ success: true, id: aliasData._id.toString() diff --git a/lib/api/messages.js b/lib/api/messages.js index 5177babe..8c8f57bd 100644 --- a/lib/api/messages.js +++ b/lib/api/messages.js @@ -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)); + }); }) ); diff --git a/lib/tools.js b/lib/tools.js index 47d78da2..99a4b2df 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -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