Skip to content

Commit

Permalink
Allow custom render callback for overridden exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
FrittenKeeZ authored Jan 30, 2025
1 parent 6969fb6 commit be52378
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Exceptions/Concerns/RendersHttpExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

trait RendersHttpExceptions
{
public function render()
public static ?\Closure $renderCallback = null;

public function render(Request $request)
{
if (Statamic::isCpRoute()) {
return response()->view('statamic::errors.'.$this->getStatusCode(), [], $this->getStatusCode());
Expand All @@ -22,6 +24,10 @@ public function render()
return response()->json(['message' => $this->getApiMessage()], $this->getStatusCode());
}

if (static::$renderCallback && ($response = call_user_func(static::$renderCallback, $request))) {
return $response;
}

if ($cached = $this->getCachedError()) {
return $cached;
}
Expand Down

0 comments on commit be52378

Please sign in to comment.