2017-02-19 22:02:03 +00:00
|
|
|
<?php
|
2017-11-17 01:23:18 +00:00
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
2017-02-19 22:02:03 +00:00
|
|
|
declare(strict_types=1);
|
2017-03-28 04:12:12 +00:00
|
|
|
namespace JKingWeb\Arsse\Feed;
|
2017-02-19 22:02:03 +00:00
|
|
|
|
2020-01-23 22:07:20 +00:00
|
|
|
use GuzzleHttp\Exception\BadResponseException;
|
2020-01-21 13:42:38 +00:00
|
|
|
use GuzzleHttp\Exception\GuzzleException;
|
2020-01-23 22:07:20 +00:00
|
|
|
use GuzzleHttp\Exception\TooManyRedirectsException;
|
|
|
|
use PicoFeed\PicoFeedException;
|
2020-01-21 13:42:38 +00:00
|
|
|
|
2017-03-28 04:12:12 +00:00
|
|
|
class Exception extends \JKingWeb\Arsse\AbstractException {
|
2017-02-19 22:02:03 +00:00
|
|
|
public function __construct($url, \Throwable $e) {
|
2020-01-23 22:07:20 +00:00
|
|
|
if ($e instanceof BadResponseException) {
|
2020-01-21 13:42:38 +00:00
|
|
|
switch ($e->getCode()) {
|
|
|
|
case 401:
|
|
|
|
$msgID = "unauthorized";
|
|
|
|
break;
|
|
|
|
case 403:
|
|
|
|
$msgID = "forbidden";
|
|
|
|
break;
|
|
|
|
case 404:
|
|
|
|
case 410:
|
|
|
|
$msgID = "invalidUrl";
|
|
|
|
break;
|
|
|
|
case 508:
|
|
|
|
$msgID = "tooManyRedirects";
|
|
|
|
break;
|
|
|
|
default:
|
2020-01-24 20:54:08 +00:00
|
|
|
$msgID = "transmissionError";
|
2020-01-21 13:42:38 +00:00
|
|
|
}
|
2020-01-23 22:07:20 +00:00
|
|
|
} elseif ($e instanceof TooManyRedirectsException) {
|
|
|
|
$msgID = "maxRedirect";
|
|
|
|
} elseif ($e instanceof GuzzleException) {
|
|
|
|
$m = $e->getMessage();
|
|
|
|
if (preg_match("/^Error creating resource:/", $m)) {
|
|
|
|
// PHP stream error; the class of error is ambiguous
|
|
|
|
$msgID = "transmissionError"; // @codeCoverageIgnore
|
|
|
|
} elseif (preg_match("/^cURL error 35:/", $m)) {
|
|
|
|
$msgID = "invalidCertificate";
|
|
|
|
} elseif (preg_match("/^cURL error 28:/", $m)) {
|
|
|
|
$msgID = "timeout";
|
|
|
|
} else {
|
|
|
|
var_export($m);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
} elseif ($e instanceof PicoFeedException) {
|
2020-01-21 13:42:38 +00:00
|
|
|
$className = get_class($e);
|
|
|
|
// Convert the exception thrown by PicoFeed to the one to be thrown here.
|
2020-01-23 22:07:20 +00:00
|
|
|
$msgID = preg_replace('/^PicoFeed\\\(?:Client|Parser|Reader)\\\([A-Za-z]+)Exception$/', '$1', $className);
|
2020-01-21 13:42:38 +00:00
|
|
|
// If the message ID doesn't change then it's unknown.
|
|
|
|
$msgID = ($msgID !== $className) ? lcfirst($msgID) : '';
|
2020-01-23 22:07:20 +00:00
|
|
|
} else {
|
|
|
|
$msgID = get_class($e);
|
2020-01-21 13:42:38 +00:00
|
|
|
}
|
2017-02-19 22:02:03 +00:00
|
|
|
parent::__construct($msgID, ['url' => $url], $e);
|
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
}
|