Format response for validation errors
This commit is contained in:
parent
44fda787d3
commit
9363873898
@ -71,8 +71,25 @@ export default abstract class Application {
|
||||
}
|
||||
|
||||
if (err instanceof ValidationBag) {
|
||||
req.flash('validation', err.getMessages());
|
||||
res.redirectBack();
|
||||
res.format({
|
||||
json: () => {
|
||||
res.status(401);
|
||||
res.json({
|
||||
status: 'error',
|
||||
code: 401,
|
||||
message: 'Invalid form data',
|
||||
messages: err.getMessages(),
|
||||
});
|
||||
},
|
||||
text: () => {
|
||||
res.status(401);
|
||||
res.send('Error: ' + err.getMessages())
|
||||
},
|
||||
html: () => {
|
||||
req.flash('validation', err.getMessages());
|
||||
res.redirectBack();
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user