1 | <?php |
||
17 | class CatchUserException extends AbstractMiddleware |
||
18 | { |
||
19 | |||
20 | use LoggerTrait; |
||
21 | |||
22 | /** |
||
23 | * {@inheritdoc} |
||
24 | */ |
||
25 | 5 | public function processException(Request $request, Exception $exception) |
|
26 | { |
||
27 | 5 | if ($exception instanceof ResourceNotFoundException) { |
|
28 | 2 | $exception = new UserException(sprintf('Page not found: %s', $request->getRequestUri()), 0, $exception); |
|
29 | 2 | $response = new Response('', 404); |
|
30 | 5 | } elseif ($exception instanceof MethodNotAllowedException) { |
|
31 | 1 | $exception = new UserException( |
|
32 | 1 | sprintf( |
|
33 | 1 | 'You are not allowed to access the page. Allowed methods: %s', |
|
34 | 1 | implode(',', $exception->getAllowedMethods()) |
|
35 | 1 | ), |
|
36 | 1 | 0, |
|
37 | $exception |
||
38 | 1 | ); |
|
39 | 1 | $response = new Response('', 405); |
|
40 | 3 | } elseif ($exception instanceof UserException) { |
|
41 | // just pass a UserException to Frontend |
||
42 | 1 | $response = new Response('', 500); |
|
43 | 1 | } else { |
|
44 | 1 | $exception = new UserException($exception->getMessage(), 0, $exception); |
|
45 | 1 | $response = new Response('', 500); |
|
46 | } |
||
47 | |||
48 | 5 | $this->error($exception->getMessage()); |
|
49 | 5 | $this->error($exception->getTraceAsString()); |
|
50 | |||
51 | 5 | $this->setMessage($exception, $response); |
|
52 | |||
53 | 5 | return $response; |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * @param Exception $exception |
||
58 | * @param Response $response |
||
59 | */ |
||
60 | 5 | protected function setMessage(Exception $exception, Response $response) |
|
67 | } |
||
68 |