Observable.throw from controller results in unhandled rejection promise
See original GitHub issueHi 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:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
thanks 😃 will publish fix during this week
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.