fix: align JIT/dynamic mode with AOT for parse errors and status codes#1819
Open
eL1fe wants to merge 1 commit intoelysiajs:mainfrom
Open
fix: align JIT/dynamic mode with AOT for parse errors and status codes#1819eL1fe wants to merge 1 commit intoelysiajs:mainfrom
eL1fe wants to merge 1 commit intoelysiajs:mainfrom
Conversation
Multiple inconsistencies between AOT and JIT (aot: false) modes in how
lifecycle hooks handle errors and body parsing:
1. ElysiaCustomStatusResponse thrown from onRequest/onParse was not
recognized by the dynamic error handler, returning 500 instead of
the specified status code.
2. Body parsing errors in dynamic mode were not wrapped in ParseError
(status 400) like in AOT mode, causing raw 500 errors.
3. Parse hooks (including string parsers like "text") were only invoked
when Content-Type header was present, unlike AOT which runs them
unconditionally.
4. Short parser aliases ("text", "json", etc.) in route-level content
config were not matched in the dynamic handler's switch statement.
Fixes elysiajs#1753
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Multiple behavioral inconsistencies between AOT and JIT (
aot: false) modes, all insrc/dynamic-handle.ts.Problems fixed
1.
ElysiaCustomStatusResponsenot handled in dynamic error handlerThrowing
status(401)fromonRequestreturned 500 instead of 401.2. Body parsing errors not wrapped in
ParseErrorErrors during body parsing returned raw 500 instead of 400 Bad Request (AOT wraps in
ParseError).3. Parse hooks skipped without Content-Type header
Parse hooks (including string parsers like
"text") were nested insideif (contentType), so they never ran when the Content-Type header was missing. AOT runs them unconditionally.4. Short parser aliases not matched
Route-level
parse: "text"storedcontent = undefinedandhooks.parse = ["text"], but the dynamic handler's switch only matched full MIME types like"text/plain". Added short aliases ("json","text","urlencoded","arrayBuffer","formdata").Before/After
Test plan
Fixes #1753