forked from VantaFinance/daDataClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInternalServerMiddleware.php
More file actions
33 lines (26 loc) · 1.03 KB
/
InternalServerMiddleware.php
File metadata and controls
33 lines (26 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
/**
* DaData Client
*
* @author Vlad Shashkov <v.shashkov@pos-credit.ru>
* @copyright Copyright (c) 2023, The Vanta
*/
declare(strict_types=1);
namespace Vanta\Integration\DaData\Infrastructure\HttpClient\Middleware;
use Psr\Http\Message\RequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Vanta\Integration\DaData\Infrastructure\HttpClient\ConfigurationClient;
use Vanta\Integration\DaData\Infrastructure\HttpClient\Exception\InternalServerErrorException;
use Yiisoft\Http\Status;
final class InternalServerMiddleware implements Middleware
{
public function process(Request $request, ConfigurationClient $configuration, callable $next): Response
{
$response = $next($request, $configuration);
$statusCode = $response->getStatusCode();
if (!(Status::INTERNAL_SERVER_ERROR <= $statusCode && $statusCode <= Status::NETWORK_AUTHENTICATION_REQUIRED)) {
return $response;
}
throw InternalServerErrorException::create($response, $request);
}
}