Answer the question
In order to leave comments, you need to log in
How to properly handle errors for an API response?
The question arose, for a successful answer is always good and convenient to give?
For example, interrupt at: throw new Exception(77, 'Не верный формат!')
and the answer will be:
{success: false, message: 'Не верный формат!', errorCode: 77}
return [ "success" => false, "message" => 'Не верный формат!', "errorCode" => 77];
Answer the question
In order to leave comments, you need to log in
And if rest is used, then you can return just text and a 400 error.
I have so:
function error($string)
{
$arr = array('answer' => 'error', 'string' => $string);
echo json_encode($arr);
exit;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question