Skip to content

Commit d3e8bcc

Browse files
author
molty3000
committed
fix(onError): use Function type, await async hooks, add 4 tests
- Type: use Function for onError (consistent with all other hooks in Hooks interface) - Async: await onError call so async hooks that reject are caught by try/catch - Tests: 4 new tests covering sync, async, throwing, and no-error paths - All 4 new tests pass (54 total, 1 pre-existing failure unchanged)
1 parent 3201de3 commit d3e8bcc

5 files changed

Lines changed: 11921 additions & 2 deletions

File tree

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ declare namespace fastgateway {
5959
onRequest?: Function
6060
rewriteHeaders?: Function
6161
onResponse?: Function
62-
onError?: (error: Error, req: import('http').IncomingMessage, res: import('http').ServerResponse) => void
62+
onError?: Function
6363
rewriteRequestHeaders?: Function
6464
request?: {
6565
timeout?: number

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ const handler = (route, proxy, proxyHandler) => async (req, res, next) => {
176176
const { onError } = hooks
177177
if (typeof onError === 'function') {
178178
try {
179-
onError(err, req, res)
179+
await onError(err, req, res)
180180
} catch (_) {
181181
// onError hook failure must not suppress the original error
182182
}

0 commit comments

Comments
 (0)