notiz-dev / nestjs-prisma

Easy Prisma support for your NestJS application
https://nestjs-prisma.dev
MIT License
587 stars 50 forks source link

`response.status is not a function` when using PrismaClientExceptionFilter #58

Closed Webbly25 closed 1 year ago

Webbly25 commented 1 year ago

I am using graphql and whenever I get any error (duplicate key, not found, ...) I get the following:

{
  "data": {},
  "errors": [
    {
      "message": "response.status is not a function",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "userCreate"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "stacktrace": [
          "TypeError: response.status is not a function",
          "    at ExpressAdapter.reply (C:\\Users\\Ryan\\Documents\\Projects\\Rhyno\\nest-rhyno-v2\\node_modules\\@nestjs\\platform-express\\adapters\\express-adapter.js:28:22)",
          "    at PrismaClientExceptionFilter.catch (C:\\Users\\Ryan\\Documents\\Projects\\Rhyno\\nest-rhyno-v2\\node_modules\\@nestjs\\core\\exceptions\\base-exception-filter.js:28:28)",
          "    at PrismaClientExceptionFilter.catchClientKnownRequestError (C:\\Users\\Ryan\\Documents\\Projects\\Rhyno\\nest-rhyno-v2\\node_modules\\nestjs-prisma\\lib\\prisma-client-exception.filter.ts:88:16)",
          "    at PrismaClientExceptionFilter.catch (C:\\Users\\Ryan\\Documents\\Projects\\Rhyno\\nest-rhyno-v2\\node_modules\\nestjs-prisma\\lib\\prisma-client-exception.filter.ts:69:19)",
          "    at ExternalExceptionsHandler.invokeCustomFilters (C:\\Users\\Ryan\\Documents\\Projects\\Rhyno\\nest-rhyno-v2\\node_modules\\@nestjs\\core\\exceptions\\external-exceptions-handler.js:34:32)",
          "    at ExternalExceptionsHandler.next (C:\\Users\\Ryan\\Documents\\Projects\\Rhyno\\nest-rhyno-v2\\node_modules\\@nestjs\\core\\exceptions\\external-exceptions-handler.js:13:29)",
          "    at Object.userCreate (C:\\Users\\Ryan\\Documents\\Projects\\Rhyno\\nest-rhyno-v2\\node_modules\\@nestjs\\core\\helpers\\external-proxy.js:14:42)"
        ]
      }
    }
  ]
}

I tried adding the filter by using APP_FILTER in my app.module.ts and also by using app.useGlobalFilters(new PrismaClientExceptionFilter(httpAdapter));

marcjulian commented 1 year ago

Hi @Webbly25 which version are you using? Do you have a reproduction repo?

Webbly25 commented 1 year ago

I have just made a repo with an example of the error: Repo. If you run the gql:

query User {
  user(id: 9999) {
    name
  }
}

You will get the error which should be User not found.

nestjs-prisma is version 0.20.0

rhazen35 commented 1 year ago

@marcjulian @Webbly25 Can confirm the issue on v0.20.0. Downgraded to v0.19.0 and the expected error is shown. Seems to me that the issue is in v0.20.0.

marcjulian commented 1 year ago

Thank you @Webbly25 for the reproduction repo. I was able to fix the bug and added a GraphQL Example to test it out the in the future.

Please test it out with the latest bug release

npm i nestjs-prisma@0.20.1