Skip to content

fix: align JIT/dynamic mode with AOT for parse errors and status codes#1819

Open
eL1fe wants to merge 1 commit intoelysiajs:mainfrom
eL1fe:fix/aot-non-aot-consistency
Open

fix: align JIT/dynamic mode with AOT for parse errors and status codes#1819
eL1fe wants to merge 1 commit intoelysiajs:mainfrom
eL1fe:fix/aot-non-aot-consistency

Conversation

@eL1fe
Copy link

@eL1fe eL1fe commented Mar 25, 2026

Summary

Multiple behavioral inconsistencies between AOT and JIT (aot: false) modes, all in src/dynamic-handle.ts.

Problems fixed

1. ElysiaCustomStatusResponse not handled in dynamic error handler

Throwing status(401) from onRequest returned 500 instead of 401.

2. Body parsing errors not wrapped in ParseError

Errors 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 inside if (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" stored content = undefined and hooks.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 case AOT JIT (before) JIT (after)
onParse throw 413, no Content-Type 400 200 "echoing undefined" 400
onParse throw 413, with Content-Type 400 500 400
onRequest throw 401, no Content-Type 401 500 401
onRequest throw 401, with Content-Type 401 500 401

Test plan

  • All 4 discrepancies from the issue now match AOT behavior
  • Full test suite passes (1525 pass, 0 fail)

Fixes #1753

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistencies between AOT and non-AOT on parsing and body handling

1 participant