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

[5.x] Allow custom render callback for overridden exceptions #11408

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Exceptions/Concerns/RendersHttpExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Statamic\Exceptions\Concerns;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Statamic\Facades\Cascade;
Expand All @@ -12,8 +13,14 @@

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

public function render(Request $request)
{
if (static::$renderCallback && ($response = Closure::fromCallable(static::$renderCallback)->call($this, $request))) {
return $response;
}

if (Statamic::isCpRoute()) {
return response()->view('statamic::errors.'.$this->getStatusCode(), [], $this->getStatusCode());
}
Expand Down Expand Up @@ -82,4 +89,9 @@ private function getCachedError(): ?Response
? $cacher->getCachedPage($request)->toResponse($request)
: null;
}

public static function renderUsing(Closure $callback): void
{
static::$renderCallback = $callback;
}
}