I'm working on an API and am trying to report back to the consumers certain errors (e.g. input errors, errors that occur during the processing of their requests, etc.). My API returns an array of errors (and warnings, and notices).
I'm starting to see a couple of problems:
- I'm not completely DRY. A number of the errors, warnings, and notices tend to occur repeatedly in different parts of the code. So, at these different parts of the code, I'm having to set the error's code, title, description repeatedly (the descriptions tend to have more specific details about the particular error, so one could argue that this difference does make it DRY -- but the code and title are the same, so not-DRY).
- My classes (parent, child) are getting bloated with all the code to handle errors, warnings, notices.
I'm tempted to create a class that just contains errors, warnings, and notices (probably in the form of a massive array). Perhaps I make it a base class -- and my current base class would just extend that. I could make some sort of method in it to make it easier for the classes that extend it to add errors (there is a protected member for errors, warnings, notices).
What's a good approach? Using PHP.