mirror of
https://github.com/typicode/json-server.git
synced 2025-08-02 02:53:21 +08:00
Update DELETE to return 404 if resource doesn't exist
This commit is contained in:
@ -230,7 +230,7 @@ module.exports = function (db, name) {
|
||||
|
||||
// DELETE /name/:id
|
||||
function destroy (req, res, next) {
|
||||
db(name).removeById(utils.toNative(req.params.id))
|
||||
var resource = db(name).removeById(utils.toNative(req.params.id))
|
||||
|
||||
// Remove dependents documents
|
||||
var removable = db._.getRemovable(db.object)
|
||||
@ -239,7 +239,10 @@ module.exports = function (db, name) {
|
||||
db(item.name).removeById(item.id)
|
||||
})
|
||||
|
||||
if (resource) {
|
||||
res.locals.data = {}
|
||||
}
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
|
@ -474,6 +474,14 @@ describe('Server', function () {
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should respond with 404 if resource is not found', function (done) {
|
||||
request(server)
|
||||
.del('/posts/9001')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect({})
|
||||
.expect(404, done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Static routes', function () {
|
||||
|
Reference in New Issue
Block a user