mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01:00
fix(http-status): Client errors should use 400 status codes
This commit is contained in:
parent
9c76a12356
commit
e256db29a5
@ -8,6 +8,19 @@ class NameExistsError extends Error {
|
||||
this.name = this.constructor.name;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
const obj = {
|
||||
isJoi: true,
|
||||
name: this.constructor.name,
|
||||
details: [
|
||||
{
|
||||
message: this.message,
|
||||
},
|
||||
],
|
||||
};
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NameExistsError;
|
||||
|
@ -104,9 +104,12 @@ test('should not be allowed to reuse active toggle name', t => {
|
||||
.post(`${base}/api/admin/features/validate`)
|
||||
.send({ name: 'ts' })
|
||||
.set('Content-Type', 'application/json')
|
||||
.expect(403)
|
||||
.expect(400)
|
||||
.expect(res => {
|
||||
t.true(res.body[0].msg === 'A toggle with that name already exist');
|
||||
t.true(
|
||||
res.body.details[0].message ===
|
||||
'A toggle with that name already exist'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -122,10 +125,10 @@ test('should not be allowed to reuse archived toggle name', t => {
|
||||
.post(`${base}/api/admin/features/validate`)
|
||||
.send({ name: 'ts.archived' })
|
||||
.set('Content-Type', 'application/json')
|
||||
.expect(403)
|
||||
.expect(400)
|
||||
.expect(res => {
|
||||
t.true(
|
||||
res.body[0].msg ===
|
||||
res.body.details[0].message ===
|
||||
'An archived toggle with that name already exist'
|
||||
);
|
||||
});
|
||||
|
@ -81,7 +81,7 @@ test('not be possible to override name', t => {
|
||||
return request
|
||||
.post(`${base}/api/admin/strategies`)
|
||||
.send({ name: 'Testing', parameters: [] })
|
||||
.expect(403);
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
test('update strategy', t => {
|
||||
|
@ -42,10 +42,6 @@ const handleErrors = (res, error) => {
|
||||
case 'NotFoundError':
|
||||
return res.status(404).end();
|
||||
case 'NameExistsError':
|
||||
return res
|
||||
.status(403)
|
||||
.json([{ msg: error.message }])
|
||||
.end();
|
||||
case 'ValidationError':
|
||||
return res
|
||||
.status(400)
|
||||
|
@ -151,7 +151,7 @@ test.serial('refuses to create a feature with an existing name', async t => {
|
||||
.post('/api/admin/features')
|
||||
.send({ name: 'featureX' })
|
||||
.set('Content-Type', 'application/json')
|
||||
.expect(403)
|
||||
.expect(400)
|
||||
.then(destroy);
|
||||
});
|
||||
|
||||
@ -162,7 +162,7 @@ test.serial('refuses to validate a feature with an existing name', async t => {
|
||||
.post('/api/admin/features/validate')
|
||||
.send({ name: 'featureX' })
|
||||
.set('Content-Type', 'application/json')
|
||||
.expect(403)
|
||||
.expect(400)
|
||||
.then(destroy);
|
||||
});
|
||||
|
||||
@ -201,6 +201,6 @@ test.serial('should not be possible to create archived toggle', async t => {
|
||||
strategies: [{ name: 'default' }],
|
||||
})
|
||||
.set('Content-Type', 'application/json')
|
||||
.expect(403)
|
||||
.expect(400)
|
||||
.then(destroy);
|
||||
});
|
||||
|
@ -72,7 +72,7 @@ test.serial('refuses to create a strategy with an existing name', async t => {
|
||||
.post('/api/admin/strategies')
|
||||
.send({ name: 'default', parameters: [] })
|
||||
.set('Content-Type', 'application/json')
|
||||
.expect(403)
|
||||
.expect(400)
|
||||
.then(destroy);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user