I have a GenericRepository class that provides basic functionality for interacting with persistence storage such as creating, finding, getting all, deleting, and updating data.
Within the find
method, I am searching the database using its primary key. If the data is not found, it will throw an exception.
This generic repository class serves as a base class for other classes. I desire to receive more specific error messages indicating what type of data was not found.
For example, if the find method in my OrderRepository cannot locate any data, I want the error message to state 'Order is not found' rather than the generic message 'Data not found'.
Are there established best practices to achieve this functionality?
My project is written in Typescript.