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