Member-only story
API Response error handling in the best way
A good error handling give additional information about the underlying fault, as well as lessen your time on debugging and also give user friendly feedback — readable message instead of user hanging with robot message.
I have done many web service integration. I have seen many style of response handling. Some are good and some are bad. There is some API i used gives bad response. For example,
Case 1:
failed
Case 2:
true
Case 3:
{
"message": "failed"
}
Case 4 (Good but not enough):
{
"error" : true,
"message": "Something went wrong",
}
Case 5: Troll status code. Give error message but status code 200 😑
{
"error" : true
}
But what makes its consider a good error handling?
Provide Good Error Code
Error code is the first thing will tell you what’s going on. Quality error codes will save to huge amount of time. In Case…