fix: correctly handle other errors from handlers #1033
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Author Description
Title:
This fixes an issue where some unhandled errors thrown by
tryPost
cause big issues. Due to some loose typing, it was possible for the handlers to returnnull
for aresponse
. This causes bad things as eventually it makes its way to the top of the call chain, and if you return from your last handler in hono, the context itself is returned, which is difficult to understand what is going on.Title: fix: correctly handle other errors from handlers
🔄 What Changed
response
variable asResponse | null
error: any
toerror: unknown
for better type safety🔍 Impact of the Change
📁 Total Files Changed
src/handlers/handlerUtils.ts
(12 additions, 3 deletions)🧪 Test Added
N/A
🔒 Security Vulnerabilities
N/A
Quality Recommendations
Consider adding unit tests to verify the error handling behavior
Add more specific error messages that include details about what went wrong
Consider implementing a more robust error handling strategy with custom error types