Repository navigation
chore: better error for mismatched content-type - #5654
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
|
||
| interface MinimalHandlerOpts { | ||
| req: { | ||
| headers: HTTPHeaders | Headers; |
There was a problem hiding this comment.
This could probably only take Headers and do the conversion higher up, but that's a bigger refactor for another day
There was a problem hiding this comment.
Yeah that's fine, limited number of these types right now so we can wrangle it here
| THandler extends BaseContentTypeHandler<THandlerOpts>, | ||
| >(handlers: THandler[], opts: THandlerOpts) { | ||
| const handler = handlers.find((handler) => handler.isMatch(opts)); | ||
| const contentType = new Headers(opts.req.headers as HeadersInit).get( |
| THandler extends BaseContentTypeHandler<THandlerOpts>, | ||
| >(handlers: THandler[], opts: THandlerOpts) { | ||
| const handler = handlers.find((handler) => handler.isMatch(opts)); | ||
| const contentType = new Headers(opts.req.headers as HeadersInit).get( |
There was a problem hiding this comment.
Yeah this is way better
There was a problem hiding this comment.
Does Lambda Adapter definitely behave okay? That has mixed case headers
There was a problem hiding this comment.
if it adheres to the current type (Either Record<string, string> or Record<string, string[]> it should work. Otherwise we have invalid types somewhere else
| 'content-type', | ||
| ); | ||
|
|
||
| const error = new TRPCError({ |
There was a problem hiding this comment.
Maybe we should still only create this when we actually need it? Unnecessary to create it for every request
Diagnostics ComparisonDetailsNumbers
Timings and averages
unstable timingsUnstable
|
| code: 'UNSUPPORTED_MEDIA_TYPE', | ||
| message: | ||
| 'Invalid Content-Type header. This request may not be supported by your tRPC Adapter, or possibly by tRPC at all', | ||
| 'No Content-Type header detected on the incoming request. This request may not be supported by your tRPC Adapter, or possibly by tRPC at all', |
|
This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you. |

Closes #5653
Headers(Node18+) whose.get()is case-insensitive