3
votes

So I have installed the Guzzle library version 6 according to TeamUp calendar documentation. However, when I try to run the code below I get

Fatal error: Call to undefined method GuzzleHttp\Psr7\Response::isSuccessful()  

code:

<?php
include 'vendor/autoload.php';

define('API_KEY','****ww9d5ea2b0540ba1e02c08100b0e5**');

$client = new GuzzleHttp\Client(['headers' => ['Teamup-Token' => API_KEY]]);
$res = $client->get('https://api.teamup.com/ks************/events?startDate=2016-08-21&endDate=2016-08-25');

if ($res->isSuccessful()) {
    echo $res->getBody();
    // {"event":{ ... }}
}

Shouldn't be contained in Library? Anyone?

2

2 Answers

2
votes

Yes, there is no method isSuccessful. By default Guzzle will throw exception if server return error

http://docs.guzzlephp.org/en/latest/quickstart.html

A GuzzleHttp\Exception\ServerException is thrown for 500 level errors if the http_errors request option is set to true.

A GuzzleHttp\Exception\ClientException is thrown for 400 level errors if the http_errors request option is set to true.

In the event of a networking error (connection timeout, DNS errors, etc.), a GuzzleHttp\Exception\RequestException is thrown.

Anyway, you can check the status code of the response using

$res->getStatusCode();
0
votes

The upgrade notes from Guzzle 5.0 to Guzzle 6.0 say:

GuzzleHttp\Message\Response::isSuccessful() and other related methods have been removed. Use getStatusCode() instead.