| Conditions | 5 |
| Paths | 1 |
| Total Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 36 | public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise |
||
| 37 | { |
||
| 38 | return $next($request)->then(function (ResponseInterface $response) { |
||
| 39 | switch ($response->getStatusCode()) { |
||
| 40 | case self::STATUS_OK: |
||
| 41 | return $response; |
||
| 42 | case self::STATUS_NOT_FOUND: |
||
| 43 | throw new NotFoundResultException('Result not found.'); |
||
| 44 | case self::STATUS_ERROR: |
||
| 45 | $result = json_decode($response->getBody(), true); |
||
| 46 | $errors = (array) reset($result['errors']); |
||
| 47 | |||
| 48 | foreach ($errors as $field => $error) { |
||
| 49 | $errors[$field] = "Field `{$field}` has error `{$error}`"; |
||
| 50 | } |
||
| 51 | |||
| 52 | throw new CustomErrorException(implode(', ', $errors)); |
||
| 53 | } |
||
| 54 | |||
| 55 | throw new UndefinedResultException(sprintf('Undefined result. Response Status: %s.', $response->getStatusCode())); |
||
| 56 | }); |
||
| 57 | } |
||
| 58 | } |
||
| 59 |