Skip to content
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

Middleware with Fastify cannot throw errors #2640

Closed
ssilve1989 opened this issue Jul 25, 2019 · 6 comments
Closed

Middleware with Fastify cannot throw errors #2640

ssilve1989 opened this issue Jul 25, 2019 · 6 comments

Comments

@ssilve1989
Copy link
Contributor

Bug Report

When using Fastify and attempting to throw an error the request ends up hanging yielding the error below.

Current behavior

(node:26133) UnhandledPromiseRejectionWarning: TypeError: response.status is not a function
    at FastifyAdapter.reply (/Users/stevensilvestri/dev/trumid/studio/node_modules/@nestjs/platform-fastify/adapters/fastify-adapter.js:23:22)
    at ExceptionsHandler.catch (/Users/stevensilvestri/dev/trumid/studio/node_modules/@nestjs/core/exceptions/base-exception-filter.js:41:24)
    at ExceptionsHandler.next (/Users/stevensilvestri/dev/trumid/studio/node_modules/@nestjs/core/exceptions/exceptions-handler.js:15:20)
    at /Users/stevensilvestri/dev/trumid/studio/node_modules/@nestjs/core/router/router-proxy.js:12:35
    at processTicksAndRejections (internal/process/task_queues.js:89:5)

Input Code

  async use(req: FastifyRequest, res: FastifyReply<any>, next: any) {
    throw new UnauthorizedException();

Expected behavior

Expect the response to complete with the appropriate payload

Environment

Nest version: 6.5.3

@ssilve1989 ssilve1989 added the needs triage This issue has not been looked into label Jul 25, 2019
@kamilmysliwiec
Copy link
Member

Please, provide a minimal repository which reproduces your issue.

@kamilmysliwiec kamilmysliwiec added needs clarification and removed needs triage This issue has not been looked into labels Jul 29, 2019
@thaoula
Copy link

thaoula commented Jul 30, 2019

Hi @kamilmysliwiec,

Our app is currently running in production with Express and we are trying to migrate to Fastify. However, we also have an issue with our app crashing with the error above.

If have put together a simple app to demonstrate this issue.

To test -

  1. Unzip and npm install.

To test with middleware that throws an exception inside

  1. Run npm run start.exception (this will use TestMiddleware)

To test with middleware that does not throw exception but still crashes the app

  1. Run npm run start.nocache (this will use CacheMiddleware)

  2. GET /api/test

The app will crash with - UnhandledPromiseRejectionWarning: TypeError: response.status is not a function

https://github.com/thaoula/nestjs_bugs

@kamilmysliwiec
Copy link
Member

Please, use GitHub instead (not zip archive)

@thaoula
Copy link

thaoula commented Jul 30, 2019

@kamilmysliwiec Updated the issue

@kamilmysliwiec
Copy link
Member

Fixed in 6.6.2 :)

@lock
Copy link

lock bot commented Nov 26, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants