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

Handling unknown errors #52

@robwoodgate

Description

@robwoodgate

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions