typestack / typedi

Simple yet powerful dependency injection tool for JavaScript and TypeScript.
https://docs.typestack.community/typedi/v/develop/01-getting-started
MIT License
4.07k stars 169 forks source link

fix: Catching in controllers does not have any effect when an error are thrown in another services #1376

Open joseaburt opened 3 months ago

joseaburt commented 3 months ago

Description

image

As the image shows the client is getting the exact domain service error and the controller normal try/catch does not have any effect. Something like Reflection stuff behind can be causing this.

lukaszzdanikowski commented 1 day ago

@joseaburt looking at the example it is an async/await issue - findOne is async so you should use await in line 19 of your controller - this will allow you to catch an error thrown from the service. Current code just returns rejected promise which is resolved by express, after returning from controller so outside of try block.