Conditions | 3 |
Paths | 3 |
Total Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
14 | public function __invoke(Request $request, Response $response, callable $next) |
||
15 | { |
||
16 | try { |
||
17 | $response = $next($request, $response); |
||
18 | } catch (Exception $e) { |
||
19 | $response = $this->exceptionResponse |
||
20 | ->withStatus(500) |
||
21 | ->withHeader('Content-Type', 'application/problem+json'); |
||
22 | |||
23 | $problem = new ApiProblem(); |
||
24 | $problem->setTitle($response->getReasonPhrase()); |
||
25 | $problem->setStatus(500); |
||
26 | $problem->setInstance((string) $request->getUri()); |
||
27 | |||
28 | if (getenv("APP_ENV") == "dev") { |
||
29 | $problem->setDetail($e->getMessage()); |
||
30 | } else { |
||
31 | $problem->setDetail(self::SERVER_ERROR_MESSAGE); |
||
32 | } |
||
33 | |||
34 | $response->getBody()->write($problem->asJson()); |
||
35 | } |
||
36 | |||
37 | return $response; |
||
38 | } |
||
39 | } |
||
40 |