typedi icon indicating copy to clipboard operation
typedi copied to clipboard

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

Open joseaburt opened this issue 1 year ago • 2 comments

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.

joseaburt avatar Aug 12 '24 11:08 joseaburt

@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.

lukaszzdanikowski avatar Nov 19 '24 09:11 lukaszzdanikowski

You should do return await otherwise, it will not get caught in the catch block. It's actually working as expected, not related to typedi at all.

dibyajyotiron avatar Feb 11 '25 08:02 dibyajyotiron