I am using the google api client to get a list of blogger posts (see below code).
try {
        // create service and get data
        $blogger = new \Google_Service_Blogger($this->client);
        // https://developers.google.com/blogger/docs/3.0/reference/posts/list
        // GET https://www.googleapis.com/blogger/v3/blogs/blogId/posts
        if ($this->cache->contains('posts')) {
            $posts = $this->cache->fetch('posts');
        }
        else {
            $posts = $blogger->posts->listPosts($this->bloggerId, $optParams);
            $this->cache->save('posts', $posts, 600); // 600 = 10 mins
        }
        return $posts;
        } catch (apiServiceException $e) {
        // Error from the API.
        //print 'There was an API error : ' . $e->getCode() . ' : ' . $e->getMessage();
    } catch (Exception $e) {
        //print 'There was a general error : ' . $e->getMessage();
    }
This works fine on most occasions, but occasionally I get an API error which is not caught.
Google_Service_Exception: Error calling GET https://www.googleapis.com/blogger/v3/blogs/8894809254783984374/posts?maxResults=5: (500) Backend Error at /var/www/releases/20140607051057/vendor/google/apiclient/src/Google/Http/REST.php:79)"} []
Does anyone know why this error is thrown, and how I can deal with it?
Cheers
The problem is with the namespaces. You can use the generic:
} catch (\Exception $e) {
    //print 'There was a general error : ' . $e->getMessage();
}
or, more specific:
try {
  ...
} catch (\Google_Service_Exception $e) {
  //print 'There was a general error : ' . $e->getMessage();
}
Exception is the base class for all Exceptions. See http://php.net/manual/en/class.exception.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With