May 12, 2012
What are good practices of error handling when working with API and PHP?
Question by Strawberry
So I am working with an API, and I wanted to know some good practices of handling errors without breaking the script. Throw anything at me, expose me to more so I can research it further.
Also, examples appreciated, it helps me visually link something to a term/phrase.
Some of my reads:
Answer by Starx
Error Handling, is a big big topic. It cannot be narrowed down to a single answer. Best practices are generally judge on the basis of how user friendly and secured they are. So basically your api, should have multiple feature for error alone.
- Should include a way to log the errors and display if user requires it.
- Number your errors. Give every error an unique number to identify it.
- Bring exceptions into practice. Not every errors are ACTUAL, some are exceptions.
- Multiple ways to handle the error have to be created. Liking grouping the errors at once or showing each one by one.