Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit 22c7ccb

Browse files
author
v1rtl
committed
fix onError
1 parent 17a7d11 commit 22c7ccb

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

.prettierignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

egg.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"entry": "./app.ts",
55
"description": "0-legacy, tiny & fast web framework as a replacement of Express",
66
"homepage": "https://github.com/talentlessguy/tinyhttp-deno",
7-
"version": "0.0.11",
7+
"version": "0.0.12",
88
"ignore": [
99
"./examples/**/*.ts"
1010
],

onError.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,19 @@ export type ServerError = Partial<{
1212
export type ErrorHandler = (err: ServerError, req: Request, next?: NextFunction) => void
1313

1414
export const onErrorHandler: ErrorHandler = async (err: ServerError, req: Request) => {
15-
let code = 500
15+
let code = err.code || 500
1616

17-
if (err.code && err.code in STATUS_CODES) code = err.code
18-
else if (err.status) code = err.status
17+
if (err.status) code = err.status
1918

2019
if (typeof err === 'string') {
2120
await req.respond({
2221
body: err,
2322
status: 500
2423
})
25-
} else if (code in STATUS_CODES) {
24+
} else if (STATUS_CODES.includes(code)) {
2625
await req.respond({
27-
body: status.message[code],
28-
status: 500
26+
body: status.pretty(code).toString(),
27+
status: code
2928
})
3029
} else
3130
req.respond({

0 commit comments

Comments
 (0)