question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Observable.throw from controller results in unhandled rejection promise

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
kamilmysliwieccommented, Jan 23, 2018

thanks 😃 will publish fix during this week

0reactions
lock[bot]commented, Sep 25, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NestJS: How to catch the error throw from Observable by ...
apiCallerService.post is an Observable and I tried to catch the error from ApiCallerService . But once readCreationMessage throw error (which I ...
Read more >
Unhandled Promise Rejections in Node.js - The Code Barbarian
So there's no way to make a promise library that bypasses node's unhandled rejection handler and integrates with async/await. global. Promise = ...
Read more >
Handling those unhandled promise rejections with JS async ...
[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was ......
Read more >
TypeError: "x" is not a constructor - JavaScript - MDN Web Docs
When returning an immediately-resolved or immediately-rejected Promise, you do not need to create a new Promise(...) and act on it. Instead, use the...
Read more >
48 answers on StackOverflow to the most popular Angular ...
Angular — Promise vs Observable; Difference between Constructor and ... zone.js:461 Unhandled Promise rejection: Template parse errors: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found