Skip to content

Commit

Permalink
Add throwable message to JSON error responses
Browse files Browse the repository at this point in the history
  • Loading branch information
giuscris committed Mar 1, 2025
1 parent 2ce9012 commit 4f90fb9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion formwork/src/Controllers/ErrorsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ public function error(ResponseStatus $responseStatus = ResponseStatus::InternalS
}

if ($this->request->isXmlHttpRequest()) {
$response = JsonResponse::error('Error', $responseStatus);
$message = $responseStatus->message();
if (isset($data['throwable'])) {
$message .= ': ' . $data['throwable']->getMessage();
}
$response = JsonResponse::error($message, $responseStatus);
} else {
$response = new Response($this->view(
'errors.error',
Expand Down
6 changes: 5 additions & 1 deletion formwork/src/Panel/Controllers/ErrorsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ private function makeErrorResponse(ResponseStatus $responseStatus, string $name,
}

if ($this->request->isXmlHttpRequest()) {
$response = JsonResponse::error('Error', $responseStatus);
$message = $this->translate('panel.errors.error.' . $name . '.status');
if (isset($data['throwable'])) {
$message .= ': ' . $data['throwable']->getMessage();
}
$response = JsonResponse::error($message, $responseStatus);
} else {
$response = new Response($this->view('errors.error', [
'title' => $this->translate('panel.errors.error.' . $name . '.status'),
Expand Down

0 comments on commit 4f90fb9

Please sign in to comment.