scratch – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
87 office 1 <?php
2  
3 namespace GuzzleHttp\Subscriber;
4  
5 use GuzzleHttp\Event\CompleteEvent;
6 use GuzzleHttp\Event\RequestEvents;
7 use GuzzleHttp\Event\SubscriberInterface;
8 use GuzzleHttp\Exception\RequestException;
9  
10 /**
11 * Throws exceptions when a 4xx or 5xx response is received
12 */
13 class HttpError implements SubscriberInterface
14 {
15 public function getEvents()
16 {
17 return ['complete' => ['onComplete', RequestEvents::VERIFY_RESPONSE]];
18 }
19  
20 /**
21 * Throw a RequestException on an HTTP protocol error
22 *
23 * @param CompleteEvent $event Emitted event
24 * @throws RequestException
25 */
26 public function onComplete(CompleteEvent $event)
27 {
28 $code = (string) $event->getResponse()->getStatusCode();
29 // Throw an exception for an unsuccessful response
30 if ($code[0] === '4' || $code[0] === '5') {
31 throw RequestException::create($event->getRequest(), $event->getResponse());
32 }
33 }
34 }