mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-10 18:44:04 +02:00
feat: embed response in http exception (#3847)
This commit is contained in:
24
lib/http.php
24
lib/http.php
@@ -2,7 +2,29 @@
|
||||
|
||||
class HttpException extends \Exception
|
||||
{
|
||||
// todo: should include the failing http response (if present)
|
||||
public ?Response $response;
|
||||
|
||||
public function __construct(string $message = '', int $statusCode = 0, ?Response $response = null)
|
||||
{
|
||||
parent::__construct($message, $statusCode);
|
||||
$this->response = $response ?? new Response('', 0);
|
||||
}
|
||||
|
||||
public static function fromResponse(Response $response, string $url): HttpException
|
||||
{
|
||||
$message = sprintf(
|
||||
'%s resulted in %s %s %s',
|
||||
$url,
|
||||
$response->getCode(),
|
||||
$response->getStatusLine(),
|
||||
// If debug, include a part of the response body in the exception message
|
||||
Debug::isEnabled() ? mb_substr($response->getBody(), 0, 500) : '',
|
||||
);
|
||||
if (CloudFlareException::isCloudFlareResponse($response)) {
|
||||
return new CloudFlareException($message, $response->getCode(), $response);
|
||||
}
|
||||
return new HttpException(trim($message), $response->getCode(), $response);
|
||||
}
|
||||
}
|
||||
|
||||
final class CloudFlareException extends HttpException
|
||||
|
Reference in New Issue
Block a user