mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
Changes
This commit is contained in:
36
config/promise.js
Normal file
36
config/promise.js
Normal file
@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
module.exports = function() {
|
||||
return function(req, res, next) {
|
||||
res.promise = (promise) => {
|
||||
promise
|
||||
.then((data) => {
|
||||
res.json({
|
||||
data
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
if (typeof error === 'string') {
|
||||
return res.json(400, {
|
||||
error: {
|
||||
message: error
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (error.name === 'ValidationError') {
|
||||
return res.json(400, {
|
||||
error: error
|
||||
});
|
||||
}
|
||||
|
||||
console.log(error.stack);
|
||||
res.json(500, 'Internal error');
|
||||
});
|
||||
};
|
||||
|
||||
next();
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user