Skip to content

Commit

Permalink
print stack traces of all nested exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
1ma committed Jun 23, 2023
1 parent af6402f commit 993e7d8
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/Middlewares/CrashFailsafe.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,22 @@ public function process(Message\ServerRequestInterface $request, Server\RequestH
try {
return $handler->handle($request);
} catch (Throwable $t) {
error_log((string)$t);
$stackTrace = (string)$t;

return $this->hide ?
$this->staticResponse :
$this->responseFactory->createResponse(500)
->withHeader('Content-Type', 'text/plain')
->withBody($this->responseFactory->createStream((string)$t));
while ($t->getPrevious() instanceof Throwable) {
$stackTrace .= "\n" . $t->getPrevious();
$t = $t->getPrevious();
}

error_log($stackTrace);

if ($this->hide) {
return $this->staticResponse;
}

return $this->responseFactory->createResponse(500)
->withHeader('Content-Type', 'text/plain')
->withBody($this->responseFactory->createStream($stackTrace));
}
}
}

0 comments on commit 993e7d8

Please sign in to comment.