Skip to content

Commit dd332f3

Browse files
Nyholmdbu
authored andcommitted
Clearer exception messages. (#84)
Clearer exception messages when discovery fails
1 parent cc792c2 commit dd332f3

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
### Changed
77

8+
- Made exception messages clearer. `StrategyUnavailableException` is no longer the previous exception to `DiscoveryFailedException`.
89
- `CommonClassesStrategy` is using `self` instead of `static`. Using `static` makes no sense when `CommonClassesStrategy` is final.
910

1011
## 1.1.0 - 2016-10-20

src/ClassDiscovery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected static function findOneByType($type)
7171
}
7272
}
7373

74-
throw new DiscoveryFailedException('Could not find resource using any discovery strategy', $exceptions);
74+
throw DiscoveryFailedException::create($exceptions);
7575
}
7676

7777
/**

src/Exception/DiscoveryFailedException.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,37 @@
1212
final class DiscoveryFailedException extends \Exception implements Exception
1313
{
1414
/**
15-
* @var array
15+
* @var \Exception[]
1616
*/
1717
private $exceptions;
1818

1919
/**
20-
* @param $exceptions
20+
* @param string $message
21+
* @param \Exception[] $exceptions
2122
*/
2223
public function __construct($message, array $exceptions = [])
2324
{
2425
$this->exceptions = $exceptions;
2526

26-
parent::__construct($message, 0, array_shift($exceptions));
27+
parent::__construct($message);
2728
}
2829

2930
/**
30-
* @return array
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[]
3146
*/
3247
public function getExceptions()
3348
{

0 commit comments

Comments
 (0)