| Conditions | 4 |
| Paths | 2 |
| Total Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | public function __invoke(Request $request, Response $response, \Exception $exception) |
||
| 13 | { |
||
| 14 | $statusCode = 500; |
||
| 15 | if (is_int($exception->getCode()) && $exception->getCode() >= 400 && $exception->getCode() <= 599) { |
||
| 16 | $statusCode = $exception->getCode(); |
||
| 17 | } |
||
| 18 | $className = new \ReflectionClass(get_class($exception)); |
||
| 19 | $data = [ |
||
| 20 | 'message' => $exception->getMessage(), |
||
| 21 | 'class' => $className->getShortName(), |
||
| 22 | 'status' => 'error', |
||
| 23 | 'code' => $statusCode, |
||
| 24 | ]; |
||
| 25 | $body = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); |
||
| 26 | |||
| 27 | return $response |
||
| 28 | ->withStatus($statusCode) |
||
| 29 | ->withHeader('Content-type', 'application/problem+json') |
||
| 30 | ->write($body); |
||
| 31 | } |
||
| 32 | } |
||
| 33 |