Skip to content

Commit f50c4bf

Browse files
committed
chore: don't send Content-Type header for 404 responses
See for details: https://stackoverflow.com/questions/57399153/should-content-type-header-be-set-for-404-and-204-responses
1 parent 08764b1 commit f50c4bf

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

examples/js/routes.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ app.get('/v1/categories/count', (req, res) => {
99
throw err
1010
}
1111
if (rows.length === 0) {
12-
res.type('application/json').status(404).end()
12+
res.status(404).end()
1313
return
1414
}
1515
res.json(rows[0])
@@ -26,7 +26,7 @@ app.get('/v1/collections/:collectionId/categories/count', (req, res) => {
2626
throw err
2727
}
2828
if (rows.length === 0) {
29-
res.type('application/json').status(404).end()
29+
res.status(404).end()
3030
return
3131
}
3232
res.json(rows[0])
@@ -68,7 +68,7 @@ app.get('/v1/categories/:categoryId', (req, res) => {
6868
throw err
6969
}
7070
if (rows.length === 0) {
71-
res.type('application/json').status(404).end()
71+
res.status(404).end()
7272
return
7373
}
7474
res.json(rows[0])

src/templates/routes.js.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ app.get('<%- path %>', (req, res) => {
2020
res.json(rows)
2121
<% } else { -%>
2222
if (rows.length === 0) {
23-
res.type('application/json').status(404).end()
23+
res.status(404).end()
2424
return
2525
}
2626
res.json(rows[0])

tests/crud.robot

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ GET should return a value
2626
GET should return not found
2727
${response}= Get Request api /v1/categories/100
2828
Status Should Be 404 ${response}
29-
Should Be Equal ${response.headers['Content-Type']} application/json; charset=utf-8
3029

3130
PUT should update an object
3231
&{payload}= Create Dictionary name=Fauna nameRu=Фауна slug=fauna userId=1

0 commit comments

Comments
 (0)