Skip to content
This repository has been archived by the owner on Aug 29, 2019. It is now read-only.

Handling unknown errors #52

Open
robwoodgate opened this issue Apr 15, 2016 · 0 comments
Open

Handling unknown errors #52

robwoodgate opened this issue Apr 15, 2016 · 0 comments

Comments

@robwoodgate
Copy link

robwoodgate commented Apr 15, 2016

The API has been giving non-standard errors recently (e.g. endpoint 404), which has highlighted that the library doesn't handle such "unknown errors" gracefully (it throws an array_key_exists() notice). Also, there isn't a code for APIUnreachableError...

Suggest the following change to the makeRequest() method in oauth_application.php:

if (!$resp) {
    $msg  = 'Unable to connect to the AWeber API.  (' . $this->error . ')';
    $error = array('status' => '521', 'message' => $msg, 'type' => 'APIUnreachableError',
                   'documentation_url' => 'https://labs.aweber.com/docs/troubleshooting');
    throw new AWeberAPIException($error, $url);
}

if($resp->headers['Status-Code'] >= 400) {
    $data = json_decode($resp->body, true);
    if (isset($data['error'])) {
        throw new AWeberAPIException($data['error'], $url);
    } else {
        $msg  = 'Unexpected error from AWeber API. (' . $resp->headers['Status'] . ')';
        $error = array('status' => '520', 'message' => $msg, 'type' => 'APIUnknownError',
                   'documentation_url' => 'https://labs.aweber.com/docs/troubleshooting');
        throw new AWeberAPIException($error, $url);
    }
}

Cheers
Rob

Ps - The 520/521 status codes were chosen as they correspond closely to existing "unofficial" codes:
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#CloudFlare

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

No branches or pull requests

1 participant