Overview

Namespaces

  • Contrib
    • Bundle
      • CoverallsBundle
        • Console
        • Entity
      • CoverallsV1Bundle
        • Api
        • Collector
        • Command
        • Config
        • Entity
          • Git
    • Component
      • File
      • Log
      • System
        • Git
  • Guzzle
    • Batch
      • Exception
    • Cache
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
      • QueryAggregator
    • Inflection
    • Iterator
    • Log
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Async
      • Backoff
      • Cache
      • Cookie
        • CookieJar
        • Exception
      • CurlAuth
      • ErrorResponse
        • Exception
      • History
      • Log
      • Md5
      • Mock
      • Oauth
    • Service
      • Builder
      • Command
        • Factory
        • LocationVisitor
          • Request
          • Response
      • Description
      • Exception
      • Resource
    • Stream
  • PHP
  • Psr
    • Log
  • Symfony
    • Component
      • Config
        • Definition
          • Builder
          • Exception
        • Exception
        • Loader
        • Resource
        • Util
      • Console
        • Command
        • Formatter
        • Helper
        • Input
        • Output
        • Tester
      • EventDispatcher
        • Debug
      • Finder
        • Adapter
        • Comparator
        • Exception
        • Expression
        • Iterator
        • Shell
      • Stopwatch
      • Yaml
        • Exception

Interfaces

  • HttpException

Exceptions

  • BadResponseException
  • ClientErrorResponseException
  • CouldNotRewindStreamException
  • CurlException
  • MultiTransferException
  • RequestException
  • ServerErrorResponseException
  • TooManyRedirectsException
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
 1: <?php
 2: 
 3: namespace Guzzle\Http\Exception;
 4: 
 5: use Guzzle\Http\Message\RequestInterface;
 6: use Guzzle\Http\Message\Response;
 7: 
 8: /**
 9:  * Http request exception thrown when a bad response is received
10:  */
11: class BadResponseException extends RequestException
12: {
13:     /**
14:      * @var Response
15:      */
16:     private $response;
17: 
18:     /**
19:      * Factory method to create a new response exception based on the response code.
20:      *
21:      * @param RequestInterface $request  Request
22:      * @param Response         $response Response received
23:      *
24:      * @return BadResponseException
25:      */
26:     public static function factory(RequestInterface $request, Response $response)
27:     {
28:         if ($response->isClientError()) {
29:             $label = 'Client error response';
30:             $class = __NAMESPACE__ . '\\ClientErrorResponseException';
31:         } elseif ($response->isServerError()) {
32:             $label = 'Server error response';
33:             $class = __NAMESPACE__ . '\\ServerErrorResponseException';
34:         } else {
35:             $label = 'Unsuccessful response';
36:             $class = __CLASS__;
37:             $e = new self();
38:         }
39: 
40:         $message = $label . PHP_EOL . implode(PHP_EOL, array(
41:             '[status code] ' . $response->getStatusCode(),
42:             '[reason phrase] ' . $response->getReasonPhrase(),
43:             '[url] ' . $request->getUrl(),
44:         ));
45: 
46:         $e = new $class($message);
47:         $e->setResponse($response);
48:         $e->setRequest($request);
49: 
50:         return $e;
51:     }
52: 
53:     /**
54:      * Set the response that caused the exception
55:      *
56:      * @param Response $response Response to set
57:      */
58:     public function setResponse(Response $response)
59:     {
60:         $this->response = $response;
61:     }
62: 
63:     /**
64:      * Get the response that caused the exception
65:      *
66:      * @return Response
67:      */
68:     public function getResponse()
69:     {
70:         return $this->response;
71:     }
72: }
73: 
php-coveralls API documentation generated by ApiGen 2.8.0