@@ -73,22 +73,32 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function process(Request $request, Handler $handler): Response |
75 | 75 | { |
76 | - try { |
|
76 | + try |
|
77 | + { |
|
77 | 78 | return $handler->handle($request); |
78 | - } catch (ClientException | RouterException $e) { |
|
79 | - if ($e instanceof ClientException) { |
|
79 | + } |
|
80 | + catch (ClientException | RouterException $e) |
|
81 | + { |
|
82 | + if ($e instanceof ClientException) |
|
83 | + { |
|
80 | 84 | $code = $e->getCode(); |
81 | - } else { |
|
85 | + } |
|
86 | + else |
|
87 | + { |
|
82 | 88 | $code = 404; |
83 | 89 | } |
84 | - } catch (\Throwable $e) { |
|
90 | + } |
|
91 | + catch (\Throwable $e) |
|
92 | + { |
|
85 | 93 | $snapshotter = $this->getOptional(SnapshotterInterface::class); |
86 | - if ($snapshotter !== null) { |
|
94 | + if ($snapshotter !== null) |
|
95 | + { |
|
87 | 96 | /** @var SnapshotterInterface $snapshotter */ |
88 | 97 | $snapshotter->register($e); |
89 | 98 | } |
90 | 99 | |
91 | - if (!$this->suppressErrors->suppressed()) { |
|
100 | + if (!$this->suppressErrors->suppressed()) |
|
101 | + { |
|
92 | 102 | return $this->renderError($request, $e); |
93 | 103 | } |
94 | 104 | |
@@ -111,7 +121,8 @@ discard block |
||
111 | 121 | { |
112 | 122 | $response = $this->responseFactory->createResponse(500); |
113 | 123 | |
114 | - if ($request->getHeaderLine('Accept') === 'application/json') { |
|
124 | + if ($request->getHeaderLine('Accept') === 'application/json') |
|
125 | + { |
|
115 | 126 | $response = $response->withHeader('Content-Type', 'application/json'); |
116 | 127 | $handler = new JsonHandler(); |
117 | 128 | $response->getBody()->write( |
@@ -123,10 +134,13 @@ discard block |
||
123 | 134 | ) |
124 | 135 | ) |
125 | 136 | ); |
126 | - } else { |
|
137 | + } |
|
138 | + else |
|
139 | + { |
|
127 | 140 | $handler = new HtmlHandler(); |
128 | 141 | $state = $this->getOptional(StateInterface::class); |
129 | - if ($state !== null) { |
|
142 | + if ($state !== null) |
|
143 | + { |
|
130 | 144 | $handler = $handler->withState($state); |
131 | 145 | } |
132 | 146 | |
@@ -162,9 +176,12 @@ discard block |
||
162 | 176 | */ |
163 | 177 | private function getOptional(string $class) |
164 | 178 | { |
165 | - try { |
|
179 | + try |
|
180 | + { |
|
166 | 181 | return $this->container->get($class); |
167 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
182 | + } |
|
183 | + catch (\Throwable | ContainerExceptionInterface $se) |
|
184 | + { |
|
168 | 185 | return null; |
169 | 186 | } |
170 | 187 | } |