jasontaylordev / CleanArchitecture

Clean Architecture Solution Template for ASP.NET Core
MIT License
16.84k stars 3.62k forks source link

[Question] Error Handling from Infrastructure layer #63

Closed Trigun27 closed 4 years ago

Trigun27 commented 4 years ago

Thank you for your project!

I have a REST service that I'm connecting to. The service is at Infrastructure level. But, where do I process errors of answers from REST?
As I understand it, I can't return HttpResponse to the App level because it's leaking. It's just important for the App to know if the request was successful or not.

As I see it. 1) try .. catch inside Application layer for a certain error.

2) or, make the Result class {T Data, string Error }.

In general, perhaps two approaches have their pros and cons. But which one is more in line with the philosophy

jasontaylordev commented 4 years ago

You’re welcome. Suggest looking at https://github.com/jasontaylordev/CleanArchitecture/blob/master/src/Application/Common/Interfaces/IIdentityService.cs. I’m using a result class in this case. Use a try-catch only if you can handle the error in the Infrastructure layer e.g. retry or cached, if not Result class.