Skip to content

Commit b27f02d

Browse files
committed
fix: bug where ExceptionHandler displays incorrect Exception classname
It showed the first Exception, but devs must catch the thrown Exception.
1 parent 45ce53b commit b27f02d

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

system/Debug/BaseExceptionHandler.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,14 @@ abstract public function handle(
6767
*/
6868
protected function collectVars(Throwable $exception, int $statusCode): array
6969
{
70-
$trace = $exception->getTrace();
70+
// Get the first exception.
71+
$firstException = $exception;
72+
73+
while ($prevException = $firstException->getPrevious()) {
74+
$firstException = $prevException;
75+
}
76+
77+
$trace = $firstException->getTrace();
7178

7279
if ($this->config->sensitiveDataInTrace !== []) {
7380
$trace = $this->maskSensitiveData($trace, $this->config->sensitiveDataInTrace);

system/Debug/Exceptions.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,6 @@ public function exceptionHandler(Throwable $exception)
136136
$this->request = Services::request();
137137
$this->response = Services::response();
138138

139-
// Get the first exception.
140-
while ($prevException = $exception->getPrevious()) {
141-
$exception = $prevException;
142-
}
143-
144139
if (method_exists($this->config, 'handler')) {
145140
// Use new ExceptionHandler
146141
$handler = $this->config->handler($statusCode, $exception);
@@ -325,7 +320,14 @@ protected function render(Throwable $exception, int $statusCode)
325320
*/
326321
protected function collectVars(Throwable $exception, int $statusCode): array
327322
{
328-
$trace = $exception->getTrace();
323+
// Get the first exception.
324+
$firstException = $exception;
325+
326+
while ($prevException = $firstException->getPrevious()) {
327+
$firstException = $prevException;
328+
}
329+
330+
$trace = $firstException->getTrace();
329331

330332
if ($this->config->sensitiveDataInTrace !== []) {
331333
$trace = $this->maskSensitiveData($trace, $this->config->sensitiveDataInTrace);

0 commit comments

Comments
 (0)