Validation: respond with http 400 instead of 401
This commit is contained in:
parent
b28e2b75b7
commit
42da8a68bb
@ -102,16 +102,16 @@ export default abstract class Application implements Extendable<ApplicationCompo
|
|||||||
const bag = err;
|
const bag = err;
|
||||||
res.format({
|
res.format({
|
||||||
json: () => {
|
json: () => {
|
||||||
res.status(401);
|
res.status(400);
|
||||||
res.json({
|
res.json({
|
||||||
status: 'error',
|
status: 'error',
|
||||||
code: 401,
|
code: 400,
|
||||||
message: 'Invalid form data',
|
message: 'Invalid form data',
|
||||||
messages: bag.getMessages(),
|
messages: bag.getMessages(),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
text: () => {
|
text: () => {
|
||||||
res.status(401);
|
res.status(400);
|
||||||
res.send('Error: ' + bag.getMessages());
|
res.send('Error: ' + bag.getMessages());
|
||||||
},
|
},
|
||||||
html: () => {
|
html: () => {
|
||||||
|
@ -135,7 +135,7 @@ describe('Register with username', () => {
|
|||||||
password_confirmation: 'horde_prime_will_rise',
|
password_confirmation: 'horde_prime_will_rise',
|
||||||
terms: 'on',
|
terms: 'on',
|
||||||
})
|
})
|
||||||
.expect(401);
|
.expect(400);
|
||||||
// username field should be translated from identifier
|
// username field should be translated from identifier
|
||||||
expect(res.body.messages?.username?.name).toStrictEqual('AlreadyExistsValidationError');
|
expect(res.body.messages?.username?.name).toStrictEqual('AlreadyExistsValidationError');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user