Commit bd0cca3
fix(errors): add res param to onError hook and guard against internal throw (#102)
* fix(errors): add res param to onError hook and guard against internal throw
- onError(err, req, res): response object now available for observability
- Wrap onError call in try/catch — hook failure must not suppress original error
- Type definition updated: onError?: (error: Error, request: Request, response: Response) => void
Closes #101
* fix(types): use Node http.IncomingMessage/ServerResponse for onError params
restana.Request/Response are generic types requiring Protocol<P> — incompatible
with the Hooks interface which is not parameterized. Node's native types are the
correct base types (restana extends them) and require no type arguments.
* 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)
* docs: add onError hook to lifecycle hooks documentation
* fix(test): update on-request-error assertion for restana v5.2.0
restana v5.2.0 sanitizes error messages — returns 'Internal Server Error'
instead of the thrown message. The test contract is '500 is returned',
not the specific error string.
---------
Co-authored-by: molty3000 <molty@21no.de>1 parent 944c17e commit bd0cca3
6 files changed
Lines changed: 11934 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
204 | 209 | | |
205 | 210 | | |
206 | 211 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
176 | 185 | | |
177 | 186 | | |
178 | 187 | | |
| |||
0 commit comments