1

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?

1 Answer 1

1

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.