{"action":"created","issue":{"url":"https://api.github.com/repos/nestjs/nest/issues/804","repository_url":"https://api.github.com/repos/nestjs/nest","labels_url":"https://api.github.com/repos/nestjs/nest/issues/804/labels{/name}","comments_url":"https://api.github.com/repos/nestjs/nest/issues/804/comments","events_url":"https://api.github.com/repos/nestjs/nest/issues/804/events","html_url":"https://github.com/nestjs/nest/issues/804","id":334616267,"node_id":"MDU6SXNzdWUzMzQ2MTYyNjc=","number":804,"title":"ArgumentsHost in ExceptionFilter did not return 'response' when using fastify","user":{"login":"JustGreg","id":2097571,"node_id":"MDQ6VXNlcjIwOTc1NzE=","avatar_url":"https://avatars3.githubusercontent.com/u/2097571?v=4","gravatar_id":"","url":"https://api.github.com/users/JustGreg","html_url":"https://github.com/JustGreg","followers_url":"https://api.github.com/users/JustGreg/followers","following_url":"https://api.github.com/users/JustGreg/following{/other_user}","gists_url":"https://api.github.com/users/JustGreg/gists{/gist_id}","starred_url":"https://api.github.com/users/JustGreg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JustGreg/subscriptions","organizations_url":"https://api.github.com/users/JustGreg/orgs","repos_url":"https://api.github.com/users/JustGreg/repos","events_url":"https://api.github.com/users/JustGreg/events{/privacy}","received_events_url":"https://api.github.com/users/JustGreg/received_events","type":"User","site_admin":false},"labels":[{"id":532263513,"node_id":"MDU6TGFiZWw1MzIyNjM1MTM=","url":"https://api.github.com/repos/nestjs/nest/labels/type:%20question%20%F0%9F%99%8C","name":"type: question 🙌","color":"cc317c","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-06-21T18:56:29Z","updated_at":"2018-06-22T07:54:20Z","closed_at":null,"author_association":"NONE","body":"<!--\r\nPLEASE HELP US PROCESS GITHUB ISSUES FASTER BY PROVIDING THE FOLLOWING INFORMATION.\r\n\r\nISSUES MISSING IMPORTANT INFORMATION MAY BE CLOSED WITHOUT INVESTIGATION.\r\n-->\r\n\r\n## I'm submitting a...\r\n<!-- \r\nPlease search GitHub for a similar issue or PR before submitting.\r\nCheck one of the following options with \"x\" -->\r\n<pre><code>\r\n[ ] Regression <!--(a behavior that used to work and stopped working in a new release)-->\r\n[x] Bug report\r\n[ ] Feature request\r\n[ ] Documentation issue or request\r\n[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.\r\n</code></pre>\r\n\r\n## Current behavior\r\nThe following code shoud return fastify's response, instead it returns node's [OutgoingMessage](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/index.d.ts#L1131).\r\n\r\n```ts\r\nimport { NestFactory, FastifyAdapter } from '@nestjs/core';\r\nimport { AppModule } from './modules/app.module';\r\n\r\nasync function bootstrap() {\r\n\r\n  const app = await NestFactory.create(AppModule, new FastifyAdapter());\r\n  // const app = await NestFactory.create(AppModule); // < IT WORKS WITH EXPRESS\r\n\r\n  await app\r\n    .useGlobalFilters(new AnyExceptionFilter())\r\n    .listen(3000, '0.0.0.0');\r\n\r\n}\r\n\r\nbootstrap();\r\n```\r\n\r\n```ts\r\nimport { \r\n  ExceptionFilter, Catch, \r\n  ArgumentsHost\r\n} from '@nestjs/common';\r\n\r\n@Catch()\r\nexport class AnyExceptionFilter implements ExceptionFilter {\r\n  \r\n  catch(exception: any, host: ArgumentsHost) {\r\n    const ctx = host.switchToHttp();\r\n    const response = ctx.getResponse(); // < RETURNS OutgoingMessage (Stream)\r\n\r\n\tresponse.status(500).json({ message: 'ERROR' })\r\n  }\r\n}\r\n```\r\n\r\n```\r\n UnhandledPromiseRejectionWarning: TypeError: response.status is not a function\r\n```\r\n\r\n## Expected behavior\r\n`ctx.getResponse` shoud return `response` from fastify\r\n\r\n\r\n## Environment\r\n\r\n<pre><code>\r\nNest version: 5.0.1\r\n<!-- Check whether this is still an issue in the most recent Nest version -->\r\n \r\nFor Tooling issues:\r\n- Node version: 10.4.1  <!-- run `node --version` -->\r\n- Platform: Linux <!-- Mac, Linux, Windows -->\r\n\r\nOthers:\r\n<!-- Anything else relevant?  Operating system version, IDE, package manager, ... -->\r\n</code></pre>\r\n"},"comment":{"url":"https://api.github.com/repos/nestjs/nest/issues/comments/399355718","html_url":"https://github.com/nestjs/nest/issues/804#issuecomment-399355718","issue_url":"https://api.github.com/repos/nestjs/nest/issues/804","id":399355718,"node_id":"MDEyOklzc3VlQ29tbWVudDM5OTM1NTcxOA==","user":{"login":"JustGreg","id":2097571,"node_id":"MDQ6VXNlcjIwOTc1NzE=","avatar_url":"https://avatars3.githubusercontent.com/u/2097571?v=4","gravatar_id":"","url":"https://api.github.com/users/JustGreg","html_url":"https://github.com/JustGreg","followers_url":"https://api.github.com/users/JustGreg/followers","following_url":"https://api.github.com/users/JustGreg/following{/other_user}","gists_url":"https://api.github.com/users/JustGreg/gists{/gist_id}","starred_url":"https://api.github.com/users/JustGreg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JustGreg/subscriptions","organizations_url":"https://api.github.com/users/JustGreg/orgs","repos_url":"https://api.github.com/users/JustGreg/repos","events_url":"https://api.github.com/users/JustGreg/events{/privacy}","received_events_url":"https://api.github.com/users/JustGreg/received_events","type":"User","site_admin":false},"created_at":"2018-06-22T07:54:20Z","updated_at":"2018-06-22T07:54:20Z","author_association":"NONE","body":"I used the code from https://github.com/nestjs/nest/tree/v5.0.1/sample/10-fastify\r\nwith this changes:\r\n\r\ncat src/main.ts\r\n```ts\r\nimport { NestFactory, FastifyAdapter } from '@nestjs/core';\r\nimport { ValidationPipe } from '@nestjs/common';\r\nimport { ApplicationModule } from './app.module';\r\nimport { AnyExceptionFilter } from './common/filters/exception.filter';\r\n\r\nasync function bootstrap() {\r\n  const app = await NestFactory.create(ApplicationModule, new FastifyAdapter());\r\n  app.useGlobalPipes(new ValidationPipe())\r\n    .useGlobalFilters(new AnyExceptionFilter()); // < Exception Filter\r\n  await app.listen(3000);\r\n}\r\nbootstrap();\r\n```\r\n\r\ncat src/app.module.ts\r\n```ts\r\nimport { Module, MiddlewareConsumer, RequestMethod } from '@nestjs/common';\r\nimport { CatsModule } from './cats/cats.module';\r\nimport { TestMiddleware } from './common/middlewares/test.middleware';\r\n\r\n@Module({\r\n  imports: [CatsModule],\r\n})\r\nexport class ApplicationModule {\r\n  public configure(consumer: MiddlewareConsumer): void {\r\n\t// add middleware\r\n    consumer.apply(TestMiddleware).forRoutes({ path: '/', method: RequestMethod.ALL});\r\n  }\r\n}\r\n```\r\n\r\nsrc/common/middlewares/test.middleware.ts\r\n```ts\r\nimport {\r\n  Injectable, MiddlewareFunction,\r\n  NestMiddleware, HttpException, HttpStatus,\r\n} from '@nestjs/common';\r\n\r\n@Injectable()\r\nexport class TestMiddleware implements NestMiddleware {\r\n  resolve(options: any): MiddlewareFunction {\r\n    return (req, res, next) => {\r\n      throw new HttpException('Auth failed', HttpStatus.FORBIDDEN); // Throw Error\r\n      next();\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nsrc/common/filters/exception.filter.ts\r\n```ts\r\nimport {\r\n  ExceptionFilter, Catch,\r\n  ArgumentsHost\r\n} from '@nestjs/common';\r\n\r\n@Catch()\r\nexport class AnyExceptionFilter implements ExceptionFilter {\r\n\r\n  catch(exception: any, host: ArgumentsHost) {\r\n    const ctx = host.switchToHttp();\r\n    const response = ctx.getResponse(); // < RETURNS OutgoingMessage\r\n\r\n    response.code(500).send({ message: 'ERROR' });\r\n\t// UnhandledPromiseRejectionWarning: TypeError: response.code is not a function\r\n  }\r\n}\r\n```\r\n"}}
{"actor":{"display_login":"JustGreg"}}