Skip to content

Commit ff65ae4

Browse files
authored
Merge pull request #3810 from lucabk/patch-1
Update part3c.md
2 parents 3ed70de + 90c58b1 commit ff65ae4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/content/3/en/part3c.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,8 @@ app.delete('/api/notes/:id', (request, response, next) => {
855855
})
856856
```
857857

858-
In both of the "successful" cases of deleting a resource, the backend responds with the status code <i>204 no content</i>. The two different cases are deleting a note that exists, and deleting a note that does not exist in the database. The _result_ callback parameter could be used for checking if a resource was actually deleted, and we could use that information for returning different status codes for the two cases if we deem it necessary. Any exception that occurs is passed onto the error handler.
858+
In both of the "successful" cases of deleting a resource, the backend responds with the status code <i>204 no content</i>. The two different cases are deleting a note that exists, and deleting a note that does not exist in the database. The _result_ callback parameter could be used for checking if a resource was actually deleted, and we could use that information for returning different status codes for the two cases if we deem it necessary. Similarly, when sending a PUT request with a non-existent ID, it returns null, but the error isn't caught by the catch block, requiring additional handling. Any other exception that occurs is passed onto the error handler.
859+
859860

860861
The toggling of the importance of a note can be easily accomplished with the [findByIdAndUpdate](https://mongoosejs.com/docs/api/model.html#model_Model-findByIdAndUpdate) method.
861862

@@ -870,6 +871,8 @@ app.put('/api/notes/:id', (request, response, next) => {
870871

871872
Note.findByIdAndUpdate(request.params.id, note, { new: true })
872873
.then(updatedNote => {
874+
if(!updatedNote)
875+
return res.status(400).json({ error: 'Note not found' })
873876
response.json(updatedNote)
874877
})
875878
.catch(error => next(error))

0 commit comments

Comments
 (0)