2020-04-13 00:02:40 +00:00
|
|
|
var router = require('express').Router();
|
|
|
|
|
|
|
|
router.use('/', require('./users'));
|
|
|
|
router.use('/profiles', require('./profiles'));
|
|
|
|
router.use('/tracks', require('./tracks'));
|
|
|
|
router.use('/tags', require('./tags'));
|
2020-10-20 19:25:00 +00:00
|
|
|
router.use('/accounts', require('../../accounts/accounts.controller'));
|
2020-04-13 00:02:40 +00:00
|
|
|
|
2020-10-20 19:25:00 +00:00
|
|
|
router.use(function (err, req, res, next) {
|
|
|
|
if (err.name === 'ValidationError') {
|
2020-04-13 00:02:40 +00:00
|
|
|
return res.status(422).json({
|
2020-10-20 19:25:00 +00:00
|
|
|
errors: Object.keys(err.errors).reduce(function (errors, key) {
|
2020-04-13 00:02:40 +00:00
|
|
|
errors[key] = err.errors[key].message;
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}, {})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return next(err);
|
|
|
|
});
|
|
|
|
|
2020-08-14 10:37:34 +00:00
|
|
|
module.exports = router;
|