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:

Error handling in PHP

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.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!