C#C
C#3y ago
Filomeon

❔ Data Layer communicating ultimately to API controller

Hello 👋
I was wondering if someone has a best practice for this? 😁

I want that my Data Access Layer (Repository using Entity framework) communicates to my API controller to tell it if :

1) If the item to update was not found with corresponding ID in DB
2) If the item to update can not be updated because some item in DB already uses its UNIQUE name
3) If the item has successfully been updated

Usually I return to my API the Item if success, or null if not found. But here, I must also communicate if item with unique name already exists, and the controller must know so that I can return valuable info to the API consumer.

Do you think that throwing Exception from the data access layer, bubbling it to my Business Layer, and finally catching it in my API Controller is a good idea?

I have doubts because some people say exceptions should really be exceptional, and I don't feel like these Database Update impossibilities are really exceptional ? 🤔
Is there another better way to do this ?

Any help will be very much appreciated ! 👍
Was this page helpful?