XeroAPI / php-oauth2-example

A PHP example of the OAuth 2.0 flow and Xero's API without the use of an SDK
MIT License
2 stars 5 forks source link

Checking for errors with $request #1

Open fmdataweb opened 3 years ago

fmdataweb commented 3 years ago

Is there a way to check for any errors with the actual Xero API request (e.g. the GET Organisation request on line 75 of the index.php file):

    $request = $provider->getAuthenticatedRequest(
        'GET',
        'https://api.xero.com/api.xro/2.0/Organisation',
        $accessToken,
        $options
    );

I would like to add in some error checking to see if this request was successful and returned a 200 response (and not a 400 etc) - is there an built in way to do this?

ajpgtech commented 3 years ago

This is not an issue but a support call. Please redirect

However, to guide you, use a try catch

    try {
         ... your code
    } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
        // Failed to get the access token or user details.
        exit($e->getMessage());
    }