Skip to content

Commit b9fe429

Browse files
committed
Merge pull request #96 from FriendsOfSymfony/debug-info-on-error
debug information in exceptions
2 parents 657b8c6 + b4eee37 commit b9fe429

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

src/Exception/ProxyResponseException.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,23 @@ class ProxyResponseException extends \RuntimeException implements HttpCacheExcep
1919
/**
2020
* @param string $host The host name that was contacted.
2121
* @param string $statusCode The status code of the reply.
22-
* @param string $statusMessage The content of the reply.
23-
* @param \Exception $previous The exception from guzzle.
22+
* @param string $statusMessage The error message.
23+
* @param string $details Further details about the request that caused the error.
24+
* @param \Exception $previous The exception from the HTTP client.
2425
*
2526
* @return ProxyUnreachableException
2627
*/
27-
public static function proxyResponse($host, $statusCode, $statusMessage, \Exception $previous = null)
28+
public static function proxyResponse($host, $statusCode, $statusMessage, $details = '', \Exception $previous = null)
2829
{
29-
return new ProxyResponseException(
30-
sprintf(
31-
'%s error response "%s" from caching proxy at %s',
32-
$statusCode,
33-
$statusMessage,
34-
$host
35-
),
30+
$message = sprintf(
31+
'%s error response "%s" from caching proxy at %s',
3632
$statusCode,
37-
$previous
33+
$statusMessage,
34+
$host
3835
);
36+
if ($details) {
37+
$message .= ". $details";
38+
}
39+
return new ProxyResponseException($message, $statusCode, $previous);
3940
}
4041
}

src/Exception/ProxyUnreachableException.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,25 @@ class ProxyUnreachableException extends \RuntimeException implements HttpCacheEx
1919
{
2020
/**
2121
* @param string $host The host name that was contacted.
22-
* @param string $message The error message from guzzle.
23-
* @param \Exception $previous The exception from guzzle.
22+
* @param string $message The error message from the HTTP client.
23+
* @param string $details Further details about the request that caused the error.
24+
* @param \Exception $previous The exception from the HTTP client.
2425
*
2526
* @return ProxyUnreachableException
2627
*/
27-
public static function proxyUnreachable($host, $message, \Exception $previous = null)
28+
public static function proxyUnreachable($host, $message, $details = '', \Exception $previous = null)
2829
{
30+
$message = sprintf(
31+
'Request to caching proxy at %s failed with message "%s"',
32+
$host,
33+
$message
34+
);
35+
if ($details) {
36+
$message .= ". $details";
37+
}
38+
2939
return new ProxyUnreachableException(
30-
sprintf(
31-
'Request to caching proxy at %s failed with message "%s"',
32-
$host,
33-
$message
34-
),
40+
$message,
3541
0,
3642
$previous
3743
);

src/ProxyClient/AbstractProxyClient.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ protected function handleException(MultiTransferException $exceptions)
195195
$e = ProxyUnreachableException::proxyUnreachable(
196196
$exception->getRequest()->getHost(),
197197
$exception->getMessage(),
198+
$exception->getRequest()->getRawHeaders(),
198199
$exception
199200
);
200201
} elseif ($exception instanceof RequestException) {
@@ -203,6 +204,7 @@ protected function handleException(MultiTransferException $exceptions)
203204
$exception->getRequest()->getHost(),
204205
$exception->getCode(),
205206
$exception->getMessage(),
207+
$exception->getRequest()->getRawHeaders(),
206208
$exception
207209
);
208210
} else {

0 commit comments

Comments
 (0)