Nest: Observable.throw from controller results in unhandled rejection promise

Created on 22 Jan 2018  路  5Comments  路  Source: nestjs/nest

Hi
I was using nest core @ 4.5.2, where by calls like following were not giving unhandled promise rejections.

@Controller("user")
export class UserController {
     @Get()
      find() {
          return this.userService.find .........
      }
}

In UserService

find() {
    This returns Observable.
   1. I check the permission and return boolean
   2. If permission is not present I throw exception
   3. In catch chain of observables, I log and create error event and return
       Observable.throw(....the error)
}

Above flow was working in 4.5.2 I was getting the error message in the api call response.
I updated today to 4.5.9 and code is broken now.

Basically.

@Get("/a")
    find() {
        return Observable.throw(new Error("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
    }

This has stopped working.

Error trace.

Unhandled Rejection at: Promise Promise {
  <rejected> Error: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    at UserController.findAll1 (/home/office/Data/src/project/dist/modules/user/UserController.js:27:46)
    at RouterExecutionContext.<anonymous> (/home/office/Data/src/project/node_modules/@nestjs/core/router/router-execution-context.js:51:33)
    at Generator.next (<anonymous>)
    at /home/office/Data/src/project/node_modules/@nestjs/core/router/router-execution-context.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/home/office/Data/src/project/node_modules/@nestjs/core/router/router-execution-context.js:3:12)
    at handler (/home/office/Data/src/project/node_modules/@nestjs/core/router/router-execution-context.js:49:35)
    at InterceptorsConsumer.<anonymous> (/home/office/Data/src/project/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:36:31)
    at Generator.next (<anonymous>)
    at /home/office/Data/src/project/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/home/office/Data/src/project/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:3:12)
    at InterceptorsConsumer.transformDeffered (/home/office/Data/src/project/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:35:16)
    at InterceptorsConsumer.<anonymous> (/home/office/Data/src/project/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:23:129)
    at Generator.next (<anonymous>)
    at /home/office/Data/src/project/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:7:71 } reason: Error: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    at UserController.findAll1 (/home/office/Data/src/project/dist/modules/user/UserController.js:27:46)
    at RouterExecutionContext.<anonymous> (/home/office/Data/src/project/node_modules/@nestjs/core/router/router-execution-context.js:51:33)
    at Generator.next (<anonymous>)
    at /home/office/Data/src/project/node_modules/@nestjs/core/router/router-execution-context.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/home/office/Data/src/project/node_modules/@nestjs/core/router/router-execution-context.js:3:12)
    at handler (/home/office/Data/src/project/node_modules/@nestjs/core/router/router-execution-context.js:49:35)
    at InterceptorsConsumer.<anonymous> (/home/office/Data/src/project/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:36:31)
    at Generator.next (<anonymous>)
    at /home/office/Data/src/project/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/home/office/Data/src/project/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:3:12)
    at InterceptorsConsumer.transformDeffered (/home/office/Data/src/project/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:35:16)
    at InterceptorsConsumer.<anonymous> (/home/office/Data/src/project/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:23:129)
    at Generator.next (<anonymous>)
    at /home/office/Data/src/project/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:7:71

Please advice with new version I have to do something differently.

Let me know if more information is required.

type todo 馃挌

Most helpful comment

thanks :) will publish fix during this week

All 5 comments

Hi @gbagga-trantor,
Will be fixed in the nearest patch update. Thanks for reporting :)

@kamilmysliwiec thanks for looking into it, will be waiting for next release, overall good job with respect to framework, keep it up.

thanks :) will publish fix during this week

It's fixed in v4.6.0 馃帀

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anyx picture anyx  路  3Comments

menme95 picture menme95  路  3Comments

mishelashala picture mishelashala  路  3Comments

KamGor picture KamGor  路  3Comments

tronginc picture tronginc  路  3Comments