docs.nestjs.com icon indicating copy to clipboard operation
docs.nestjs.com copied to clipboard

Microservices - Exception Filters - Add more explanation

Open mustafa-barakat opened this issue 3 years ago • 3 comments

  • [ ] Regression
  • [ ] Bug report
  • [ ] Feature request
  • [x] Documentation issue or request (new chapter/page)
  • [ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Documentation Request

Inside Exception Filtering for micro services, the example showing throw new RpcException('Invalid credentials.'); It's not right to throw the new exception as it results in another exception (I'm using KAFKA) the right thing to do is return and not throw return new RpcException('Invalid credentials.'); this will result in Error:Invalid credentials

I found the only way to throw is to have an Exception Filter and return a parsed string error there.

Reproduction Repo https://github.com/mustafa-barakat/nestjs-micro-poc

Error:

(node:27352) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Object
    at Function.from (buffer.js:330:9)
    at ServerKafka.assignErrorHeader (C:\Users\Barakat\Desktop\Projects\nestjs-micro-poc\node_modules\@nestjs\microservices\server\server-kafka.js:137:73)
    at ServerKafka.sendMessage (C:\Users\Barakat\Desktop\Projects\nestjs-micro-poc\node_modules\@nestjs\microservices\server\server-kafka.js:119:14)
    at C:\Users\Barakat\Desktop\Projects\nestjs-micro-poc\node_modules\@nestjs\microservices\server\server-kafka.js:81:31
    at C:\Users\Barakat\Desktop\Projects\nestjs-micro-poc\node_modules\@nestjs\microservices\server\server.js:46:31
    at processTicksAndRejections (internal/process/task_queues.js:79:11)
(node:27352) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:27352) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

mustafa-barakat avatar Jan 24 '22 07:01 mustafa-barakat

Please provide a minimum reproduction repository.

kamilmysliwiec avatar Jan 24 '22 08:01 kamilmysliwiec

Please provide a minimum reproduction repository.

Added

mustafa-barakat avatar Jan 24 '22 19:01 mustafa-barakat

I think this is related https://github.com/nestjs/nest/issues/8999

mustafa-barakat avatar Jan 24 '22 20:01 mustafa-barakat