Skip to content

Commit 0fc41dd

Browse files
committed
add request uri to ResourceNotFoundException
1 parent f8a84e1 commit 0fc41dd

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* (c) Packagist Conductors UG (haftungsbeschränkt) <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
namespace PrivatePackagist\ApiClient\Exception;
11+
12+
use Throwable;
13+
14+
class HttpTransportException extends RuntimeException
15+
{
16+
private $requestUri;
17+
18+
public function __construct($message = "", $code = 0, $requestUri = "", Throwable $previous = null)
19+
{
20+
$this->requestUri = $requestUri;
21+
parent::__construct($message, $code, $previous);
22+
}
23+
24+
/**
25+
* @return string
26+
*/
27+
public function getRequestUri()
28+
{
29+
return $this->requestUri;
30+
}
31+
}

src/Exception/ResourceNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
namespace PrivatePackagist\ApiClient\Exception;
1111

12-
class ResourceNotFoundException extends RuntimeException
12+
class ResourceNotFoundException extends HttpTransportException
1313
{
1414
}

src/HttpClient/Plugin/ExceptionThrower.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(ResponseMediator $responseMediator = null)
2929

3030
public function handleRequest(RequestInterface $request, callable $next, callable $first)
3131
{
32-
return $next($request)->then(function (ResponseInterface $response) {
32+
return $next($request)->then(function (ResponseInterface $response) use ($request) {
3333
if ($response->getStatusCode() < 400 || $response->getStatusCode() > 600) {
3434
return $response;
3535
}
@@ -41,7 +41,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
4141
}
4242

4343
if ($response->getStatusCode() === 404) {
44-
throw new ResourceNotFoundException($content['message'], $response->getStatusCode());
44+
throw new ResourceNotFoundException($content['message'], $response->getStatusCode(), $request->getUri());
4545
}
4646
}
4747

0 commit comments

Comments
 (0)