Skip to content

Commit 8d42c40

Browse files
authored
Fix: return JSON response for 404 errors instead of plain text (#1738)
1 parent 6ad7562 commit 8d42c40

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/app.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ await test('createApp', async (t) => {
116116
tc.statusCode,
117117
`${response.status} !== ${tc.statusCode} ${tc.method} ${tc.url} failed`,
118118
)
119+
if (tc.statusCode === 404) {
120+
const body = await response.json()
121+
assert.deepEqual(body, { error: 'Not Found' })
122+
}
119123
})
120124
}
121125

src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export function createApp(db: Low<Data>, options: AppOptions = {}) {
159159
app.use('/:name', (req, res) => {
160160
const { data } = res.locals
161161
if (data === undefined) {
162-
res.sendStatus(404)
162+
res.status(404).json({ error: 'Not Found' })
163163
} else {
164164
if (req.method === 'POST') res.status(201)
165165
res.json(data)

0 commit comments

Comments
 (0)