mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-11 00:14:50 +03:00
34 lines
944 B
PHP
34 lines
944 B
PHP
<?php
|
|
|
|
namespace GuzzleHttp\Subscriber;
|
|
|
|
use GuzzleHttp\Event\RequestEvents;
|
|
use GuzzleHttp\Event\SubscriberInterface;
|
|
use GuzzleHttp\Event\CompleteEvent;
|
|
use GuzzleHttp\Exception\RequestException;
|
|
|
|
/**
|
|
* Throws exceptions when a 4xx or 5xx response is received
|
|
*/
|
|
class HttpError implements SubscriberInterface
|
|
{
|
|
public function getEvents()
|
|
{
|
|
return ['complete' => ['onComplete', RequestEvents::VERIFY_RESPONSE]];
|
|
}
|
|
|
|
/**
|
|
* Throw a RequestException on an HTTP protocol error
|
|
*
|
|
* @param CompleteEvent $event Emitted event
|
|
* @throws RequestException
|
|
*/
|
|
public function onComplete(CompleteEvent $event)
|
|
{
|
|
$code = (string) $event->getResponse()->getStatusCode();
|
|
// Throw an exception for an unsuccessful response
|
|
if ($code[0] === '4' || $code[0] === '5') {
|
|
throw RequestException::create($event->getRequest(), $event->getResponse());
|
|
}
|
|
}
|
|
}
|