Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
router.use((err, req, res, next) => {
switch (err.name) {
// data input error
case 'ValidationError':
case 'IdNotFoundError':
case 'UpdateNotAllowedError':
case 'InvalidDateError':
case 'InvalidIncidentStatusError':
res.status(httpStatus.UNPROCESSABLE_ENTITY).json({ message: err.message });
break;
// db/unknown errors.
default:
next(err);
break;
}
});
.patch((req, res, next) => {
const data = req.sanitizedBody.component_group;
// not a valid component group object sent
if (!data || typeof data !== 'object') {
res.status(httpStatus.UNPROCESSABLE_ENTITY).json({ message: 'No component group data sent in this request.' });
}
else {
componentGroupRepo.update(req.componentGroupObj, data).then(group => {
res.json(group);
}).catch(next);
}
})
.post((req, res, next) => {
const data = req.sanitizedBody.subscription;
// not a valid subscription object sent
if (!data || typeof data !== 'object') {
res.status(httpStatus.UNPROCESSABLE_ENTITY).json({ message: 'No subscription data sent in this request.' });
}
else {
subscriptionRepo.ofType(data.type).then(repo => {
return repo.subscribe(data);
}).then(newSubscription => {
res.json(newSubscription);
}).catch(next);
}
});
router.use((err, req, res, next) => {
switch (err.name) {
// data input error
case 'InvalidCredentialsError':
res.status(httpStatus.UNPROCESSABLE_ENTITY).json({ message: err.message });
break;
// db/unknown errors.
default:
next(err);
break;
}
});
.patch((req, res, next) => {
const { incidentUpdateId } = req.sanitizedParams;
const data = req.sanitizedBody.update;
// not a valid incident object sent
if (!data || typeof data !== 'object') {
res.status(httpStatus.UNPROCESSABLE_ENTITY).json({ message: 'No update data sent in this request.' });
}
else {
// if message passed, keep the original. it could contain some html chars which will
// be sanitized later.
if (data.message) {
data.message = req.body.update.message;
}
req.repo.changeIncidentUpdateEntry(req.incidentObj, incidentUpdateId, data)
.then(updIncident => {
res.json(updIncident);
})
.catch(next);
}
router.use((err, req, res, next) => {
switch (err.name) {
// data input error
case 'ValidationError':
case 'IdNotFoundError':
case 'InvalidSubscriptionTypeError':
case 'DuplicatedSubscriptionError':
res.status(httpStatus.UNPROCESSABLE_ENTITY).json({ message: err.message });
break;
// db/unknown errors.
default:
next(err);
break;
}
});
router.use((err, req, res, next) => {
switch (err.name) {
// data input error
case 'ValidationError':
case 'IdNotFoundError':
res.status(httpStatus.UNPROCESSABLE_ENTITY).json({ message: err.message });
break;
// db/unknown errors.
default:
next(err);
break;
}
});
.catch(error => errorResponse(error.message, HttpStatus.UNPROCESSABLE_ENTITY));
}
describe('when response error is an unprocessable_entity', () => {
const error = {
response: {
status: status.UNPROCESSABLE_ENTITY,
data: {
story: {
errors: {}
}
}
}
};
it('dispatches addValidationNotifications', () => {
const FakeNotification = {
createNotification,
types
};
const fakeDispatch = sinon.stub();
(dispatch, getState, { Notification }) => {
const type = Notification.types.ERROR;
switch (error.response.status) {
case status.UNPROCESSABLE_ENTITY:
return dispatch(
addValidationNotifications(error.response.data.story.errors)
);
case status.UNAUTHORIZED:
return dispatch(
addNotification(
Notification.createNotification({
type,
message: I18n.t('users.You are not authorized to perform this action')
})
)
);
case status.NOT_FOUND:
return dispatch(
addNotification(
Notification.createNotification({