Skip to content

Commit 177ea01

Browse files
baiikoxabbuh
authored andcommitted
Fix throwable error on exception controller (#2093)
* fix(throwable): fix ExceptionController * style: remove tabulation
1 parent 42bdfed commit 177ea01

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

Controller/ExceptionController.php

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ public function __construct(
6565
public function showAction(Request $request, $exception, DebugLoggerInterface $logger = null)
6666
{
6767
$currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
68-
$code = $this->getStatusCode($exception);
68+
69+
if ($exception instanceof \Exception) {
70+
$code = $this->getStatusCode($exception);
71+
} else {
72+
$code = $this->getStatusCodeFromThrowable($exception);
73+
}
6974
$templateData = $this->getTemplateData($currentContent, $code, $exception, $logger);
7075

7176
$view = $this->createView($exception, $code, $templateData, $request, $this->showException);
@@ -101,17 +106,7 @@ protected function createView(\Exception $exception, $code, array $templateData,
101106
*/
102107
protected function getStatusCode(\Exception $exception)
103108
{
104-
// If matched
105-
if ($statusCode = $this->exceptionCodes->resolveException($exception)) {
106-
return $statusCode;
107-
}
108-
109-
// Otherwise, default
110-
if ($exception instanceof HttpExceptionInterface) {
111-
return $exception->getStatusCode();
112-
}
113-
114-
return 500;
109+
return $this->getStatusCodeFromThrowable($exception);
115110
}
116111

117112
/**
@@ -159,4 +154,26 @@ private function getAndCleanOutputBuffering($startObLevel)
159154

160155
return ob_get_clean();
161156
}
157+
158+
/**
159+
* Determines the status code to use for the response.
160+
*
161+
* @param \Throwable $exception
162+
*
163+
* @return int
164+
*/
165+
private function getStatusCodeFromThrowable(\Throwable $exception)
166+
{
167+
// If matched
168+
if ($statusCode = $this->exceptionCodes->resolveThrowable($exception)) {
169+
return $statusCode;
170+
}
171+
172+
// Otherwise, default
173+
if ($exception instanceof HttpExceptionInterface) {
174+
return $exception->getStatusCode();
175+
}
176+
177+
return 500;
178+
}
162179
}

Util/ExceptionValueMap.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ public function __construct(array $map)
4444
* @return mixed|false Value found or false is not found
4545
*/
4646
public function resolveException(\Exception $exception)
47+
{
48+
return $this->resolveThrowable($exception);
49+
}
50+
51+
/**
52+
* Resolves the value corresponding to an exception object.
53+
*
54+
* @param \Throwable $exception
55+
*
56+
* @return mixed|false Value found or false is not found
57+
*/
58+
public function resolveThrowable(\Throwable $exception)
4759
{
4860
return $this->doResolveClass(get_class($exception));
4961
}

0 commit comments

Comments
 (0)