Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error processing by the programmer instead of throw error #15

Open
wants to merge 10 commits into
base: dev-master
Choose a base branch
from

Conversation

faravaghi
Copy link

Hi, sending SMS is not always important, to stop the program in case of an error.
Instead of using throw to raise error you can return error with code and message so that the programmer can manage the error itself.

for example used this:

$json_response = json_decode($response);

if ($code != 200 && is_null($json_response)) {
    return ['message' => 'ERROR_MESSAGE', 'status' => $code];
}
else {
    $json_return = $json_response->return;
    if ($json_return->status != 200) {
        return ['message' => $json_return->message, 'status' => $json_return->status];
    }
    return ['status' => 200, 'entries' => $json_response->entries];
}

instead of :

$json_response = json_decode($response);
if ($code != 200 && is_null($json_response)) {
    throw new HttpException("Request have errors", $code);
} else {
    $json_return = $json_response->return;
    if ($json_return->status != 200) {
        throw new ApiException($json_return->message, $json_return->status);
    }
    return $json_response->entries;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants