Skip to content

fix(middleware): propagate return plain object error message instead of masking (#30)#160

Open
Heyzerohey wants to merge 3 commits into
tscircuit:mainfrom
Heyzerohey:fix/return-plain-object-error
Open

fix(middleware): propagate return plain object error message instead of masking (#30)#160
Heyzerohey wants to merge 3 commits into
tscircuit:mainfrom
Heyzerohey:fix/return-plain-object-error

Conversation

@Heyzerohey
Copy link
Copy Markdown

Closes #30.

This PR fixes the issue where returning a plain object return { ... } from a route instead of return ctx.json({ ... }) was masked as a generic 500 Internal server error in production/default exception handling.

Changes

  1. Defined ResponseObjectNotAllowedError: Added a subclass of WinterSpecMiddlewareError in src/middleware/http-exceptions.ts containing the helpful error message "Use ctx.json({...}) instead of returning an object directly." with a status of 500.
  2. Updated withResponseObjectCheck: Throw ResponseObjectNotAllowedError in src/middleware/with-response-object-check.ts instead of throwing a generic Error.
  3. Added Regression Test: Implemented a comprehensive test case in tests/middleware/with-response-object-check.test.ts verifying that returning a plain object propagates the correct error message through default exception handling.

/claim #30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When a user returns return { ... } from a route instead of return ctx.json({ ... }), throw an error telling them to use ctx.json

1 participant