AccessTokenInvalidException not working

I’m trying to handle several Exceptions, specifically “AccessTokenInvalidException”. However this doesn’t fire when I attempt to connect with a bad auth token. Instead, I get a guzzle client error.

Any ideas?

Hi @Allegory,

Could you confirm with us what version of the SDK you’re using, as well as what was your client configuration? (omitting sensitive credentials, of course).

Hello @Gabriel

SDK version 3.3

$client = new Client(Config::$contentfulKey, Config::$contentfulEnv, "master");

$query = (new Contentful\Delivery\Query())->setContentType('home');

try { 

   $entries = $client->getEntries($query);

} catch (AnyTypeOfContentfulException $e) {
    ...
}

For instance, if you attempt to use a content not found exception with the above example, it will not work. An API rate limit exception will produce a fatal (Guzzle client) error.

Any ideas?

Hey @Allegory

this code is working fine for me:

<?php

require 'vendor/autoload.php';

$client = new Contentful\Delivery\Client('someToken', 'someSpaceId', 'master');

$query = (new Contentful\Delivery\Query())->setContentType('someContentType');

try {
    $entries = $client->getEntries($query);
} catch (Contentful\Core\Exception\AccessTokenInvalidException $exception) {
    echo $exception->getMessage();
}

I’m running Contentful SDK 3.3.0 on PHP 7.1

Davide

1 Like