mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
37 lines
721 B
JavaScript
37 lines
721 B
JavaScript
'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();
|
|
};
|
|
};
|