Skip to content

Commit fecd3c3

Browse files
committed
Response: add ResourceNotFoundException for 404s
1 parent 1899d97 commit fecd3c3

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace PrivatePackagist\ApiClient\Exception;
4+
5+
class ResourceNotFoundException extends RuntimeException
6+
{
7+
}

src/HttpClient/Plugin/ExceptionThrower.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Http\Client\Common\Plugin;
66
use PrivatePackagist\ApiClient\Exception\ErrorException;
7+
use PrivatePackagist\ApiClient\Exception\ResourceNotFoundException;
78
use PrivatePackagist\ApiClient\Exception\RuntimeException;
89
use PrivatePackagist\ApiClient\HttpClient\Message\ResponseMediator;
910
use Psr\Http\Message\RequestInterface;
@@ -31,6 +32,10 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
3132
if ($response->getStatusCode() === 400) {
3233
throw new ErrorException($content['message'], $response->getStatusCode());
3334
}
35+
36+
if ($response->getStatusCode() === 404) {
37+
throw new ResourceNotFoundException($content['message'], $response->getStatusCode());
38+
}
3439
}
3540

3641
throw new RuntimeException(isset($content['message']) ? $content['message'] : $content, $response->getStatusCode());

0 commit comments

Comments
 (0)