feat(errors): Added error handling hook for observability #101
feat(errors): Added error handling hook for observability #101milkyontheblock wants to merge 2 commits into
Conversation
chore(package): add pump, husky, lint-staged, and prettier dependencies
molty3000
left a comment
There was a problem hiding this comment.
Review: Changes Requested
Overall a useful feature — the onError hook fills a real observability gap. But there are issues that should be addressed before merge.
Issues
- Wrong TypeScript type for
reqparameter (index.d.ts line 62) — uses browserRequesttype instead ofhttp.IncomingMessage - No
resparameter — error hooks without response access can't set custom error responses, limiting observability integrations - Scope creep in
package.json—pumpdependency + devDependencies reordering unrelated to error handling
Warnings
- No tests for the new
onErrorhook — 0 test coverage for the feature - Empty PR description — no motivation, usage, or changelog
- Pre-existing test failure not addressed —
(hooks) GET /users/on-request-error/info - 500already fails on master
Suggestions
- Pass
resas third parameter for richer integrations - Make hook async-signalable (return value could suppress
next(err)) - Document in README
- Add newline at EOF in demos/errors.js
See inline comments for details.
| } | ||
| } catch (err) { | ||
| const { onError } = hooks | ||
| if (typeof onError === 'function') { |
There was a problem hiding this comment.
Issue: No res parameter — The hook receives (err, req) but not res. Most observability integrations (Sentry, DataDog, NewRelic) benefit from response context — setting custom headers, logging status codes, or providing fallback error responses. Without res, users who want to return a custom error JSON body instead of the generic "Internal Server Error" can't do it here.
Consider adding res as a third parameter, or making this an async-compatible hook that can override the error response.
| onRequest?: Function | ||
| rewriteHeaders?: Function | ||
| onResponse?: Function | ||
| onError?: (error: Error, request: Request) => void |
There was a problem hiding this comment.
Issue: Wrong TypeScript type for req — Request is a browser/Fetch API type. In Node.js, the correct type is http.IncomingMessage. This will cause TypeScript compilation errors for users.
Either use http.IncomingMessage or stay consistent with the other hooks and use Function (matching the pattern of onRequest?: Function, onResponse?: Function above).
| proxyHandler(req, res, req.url, proxy, proxyOpts) | ||
| } | ||
| } catch (err) { | ||
| const { onError } = hooks |
There was a problem hiding this comment.
Issue: Return value ignored — The hook is fire-and-forget. Users who want to handle the error themselves (return a custom response, log and suppress, etc.) have no way to signal that.
Consider: if onError returns true, skip the next(err) call so the route can produce a custom error response.
| "fast-proxy-lite": "^1.1.2", | ||
| "http-cache-middleware": "^1.4.1", | ||
| "micromatch": "^4.0.8", | ||
| "pump": "^3.0.4", |
There was a problem hiding this comment.
Scope creep — Adding pump as an explicit dependency and reordering devDependencies is unrelated to the error handling feature. These changes should be in a separate PR, or at minimum called out in the PR description. pump was already available as a transitive dependency — this is a cleanup, not part of the feature.
|
|
||
| server.start(PORT).then(server => { | ||
| console.log(`API Gateway listening on ${PORT} port!`) | ||
| }) No newline at end of file |
There was a problem hiding this comment.
Minor — Missing newline at end of file (\ No newline at end of file in the diff). POSIX convention.
|
Additional finding: Linting violations in Ran
|
No description provided.