4

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?

po_taka
  • 1,816
  • 17
  • 27
bmm
  • 207
  • 1
  • 5
  • 18

2 Answers2

2

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();
po_taka
  • 1,816
  • 17
  • 27
1

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.

Matt Gibson
  • 37,886
  • 9
  • 99
  • 128