Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default exception handler #54

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
14 changes: 14 additions & 0 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,20 @@ public function execute(Route $route, Request $request): self
}
}
} catch (\Throwable $e) {
if (self::$errors === ['*' => []]) { // If no error handler are set
PineappleIOnic marked this conversation as resolved.
Show resolved Hide resolved
$response = $this->getResources(['response'])["response"];
$response->setStatusCode(500);
$response->json([
'message' => $e->getMessage(),
'stacktrace' => $e->getTrace()
]);

\fwrite(STDERR, "\033[31mException: " . $e->getMessage() . "\033[0m\n");
\fwrite(STDERR, "Stacktrace: \n" . $e->getTraceAsString() . "\n");

return $this;
}

foreach ($groups as $group) {
PineappleIOnic marked this conversation as resolved.
Show resolved Hide resolved
if (isset(self::$errors[$group])) {
foreach (self::$errors[$group] as $error) { // Group error hooks
Expand Down