Skip to content

Commit 77a3759

Browse files
committed
Fix error handling in PUT note
1 parent ff65ae4 commit 77a3759

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/content/3/en/part3c.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -871,9 +871,11 @@ app.put('/api/notes/:id', (request, response, next) => {
871871

872872
Note.findByIdAndUpdate(request.params.id, note, { new: true })
873873
.then(updatedNote => {
874-
if(!updatedNote)
875-
return res.status(400).json({ error: 'Note not found' })
876-
response.json(updatedNote)
874+
if (updatedNote) {
875+
response.json(updatedNote)
876+
} else {
877+
response.status(404).end()
878+
}
877879
})
878880
.catch(error => next(error))
879881
})

src/content/3/fi/osa3c.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,11 @@ app.put('/api/notes/:id', (request, response, next) => {
878878

879879
Note.findByIdAndUpdate(request.params.id, note, { new: true })
880880
.then(updatedNote => {
881-
response.json(updatedNote)
881+
if (updatedNote) {
882+
response.json(updatedNote)
883+
} else {
884+
response.status(404).end()
885+
}
882886
})
883887
.catch(error => next(error))
884888
})

0 commit comments

Comments
 (0)