I have a symfony project.
There is a website and a rest开发者_开发知识库 API that projects all the actions that can be done on the website.
I would like to manage the data handling (get, update, delete) for both website and API on the same code.
I realized that I need to put all the code in the MODEL so that it will be accessible via the API module and the website modules.
How do I handle errors in an Elegant way for both componenets?
I would either:
- Throw exceptions in the model methods. The exceptions can contain the message of what went wrong and your API actions / standard module actions can handle the exceptions as necessary.
- Return success/failure codes. Have your delete/update/get methods return various codes indicating what could have possibly gone wrong. Alternatively, you could return true/false and have some sort of
getLastError
method.
精彩评论