-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
104 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Shoman4eg\Nalog; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Shoman4eg\Nalog\Exception\Domain as DomainExceptions; | ||
use Shoman4eg\Nalog\Exception\DomainException; | ||
|
||
/** | ||
* @author Artem Dubinin <artem@dubinin.me> | ||
*/ | ||
final class ErrorHandler | ||
{ | ||
/** | ||
* Handle HTTP errors. | ||
* | ||
* Call is controlled by the specific API methods. | ||
* | ||
* @throws DomainException | ||
*/ | ||
public function handleResponse(ResponseInterface $response): void | ||
{ | ||
$body = (string)$response->getBody(); | ||
|
||
switch ($response->getStatusCode()) { | ||
case 400: | ||
throw new DomainExceptions\ValidationException($body); | ||
case 401: | ||
throw new DomainExceptions\UnauthorizedException($body); | ||
case 403: | ||
throw new DomainExceptions\ForbiddenException(); | ||
case 404: | ||
throw new DomainExceptions\NotFoundException(); | ||
case 406: | ||
throw new DomainExceptions\ClientException('Wrong Accept headers'); | ||
case 500: | ||
throw new DomainExceptions\ServerException(); | ||
default: | ||
throw new DomainExceptions\UnknownErrorException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters