ClassInstantiationFailedException.php
3 years ago
DiscoveryFailedException.php
3 years ago
NoCandidateFoundException.php
3 years ago
NotFoundException.php
3 years ago
PuliUnavailableException.php
3 years ago
StrategyUnavailableException.php
3 years ago
DiscoveryFailedException.php
52 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaHttp\Discovery\Exception; |
| 4 | |
| 5 | use AmeliaHttp\Discovery\Exception; |
| 6 | |
| 7 | /** |
| 8 | * Thrown when all discovery strategies fails to find a resource. |
| 9 | * |
| 10 | * @author Tobias Nyholm <tobias.nyholm@gmail.com> |
| 11 | */ |
| 12 | final class DiscoveryFailedException extends \Exception implements Exception |
| 13 | { |
| 14 | /** |
| 15 | * @var \Exception[] |
| 16 | */ |
| 17 | private $exceptions; |
| 18 | |
| 19 | /** |
| 20 | * @param string $message |
| 21 | * @param \Exception[] $exceptions |
| 22 | */ |
| 23 | public function __construct($message, array $exceptions = []) |
| 24 | { |
| 25 | $this->exceptions = $exceptions; |
| 26 | |
| 27 | parent::__construct($message); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @param \Exception[] $exceptions |
| 32 | */ |
| 33 | public static function create($exceptions) |
| 34 | { |
| 35 | $message = 'Could not find resource using any discovery strategy. Find more information at http://docs.php-http.org/en/latest/discovery.html#common-errors'; |
| 36 | foreach ($exceptions as $e) { |
| 37 | $message .= "\n - ".$e->getMessage(); |
| 38 | } |
| 39 | $message .= "\n\n"; |
| 40 | |
| 41 | return new self($message, $exceptions); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @return \Exception[] |
| 46 | */ |
| 47 | public function getExceptions() |
| 48 | { |
| 49 | return $this->exceptions; |
| 50 | } |
| 51 | } |
| 52 |