Skip to content

Upgrading to nestjs v11 (and fastify v5) does not handle invalid content-type errors from Fastify #15022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 tasks done
yawhide opened this issue Apr 25, 2025 · 3 comments
Closed
2 tasks done
Labels
needs triage This issue has not been looked into type: bug 😭

Comments

@yawhide
Copy link

yawhide commented Apr 25, 2025

Did you read the migration guide?

  • I have read the whole migration guide

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Potential Commit/PR that introduced the regression

No response

NestJS version

11.1.0

Describe the regression

FastifyError with code FST_ERR_CTP_INVALID_MEDIA_TYPE is not being rethrown as an nestjs HttpException.

I have an existing guard that validates content-type to always be application/json and raise a UnsupportedMediaTypeException if not.

But now in nestjs v11, if I make a request with an invalid content-type (say foo), my guard doesnt run and instead I see

FastifyError

code ='FST_ERR_CTP_INVALID_MEDIA_TYPE'
level ='\x1b[31merror\x1b[39m'
message ='Unsupported Media Type: foo'
name ='FastifyError'
statusCode =415

in my custom ExceptionFilter

Minimum reproduction code

https://github.com/yawhide/nestjs-issue-15022

Input code

@Catch(Error)
export class ErrorExceptionFilter extends BaseExceptionFilter {
  catch(error: Error, host: ArgumentsHost) {
    console.log(error) // error is a FastifyError, not HttpException
  }
}

Expected behavior

My custom ExceptionFilter should see an HttpException exception instead of a FastifyError when the content-type is invalid.

Other

No response

@yawhide yawhide added needs triage This issue has not been looked into type: bug 😭 labels Apr 25, 2025
@micalevisk
Copy link
Member

Please provide a minimum reproduction repository. You can start one by running npm init nest in your terminal

why reproductions are required

@yawhide
Copy link
Author

yawhide commented Apr 25, 2025

added repo

@kamilmysliwiec
Copy link
Member

Let's track this here #15056

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into type: bug 😭
Projects
None yet
Development

No branches or pull requests

3 participants