Skip to content

Commit 970ee2b

Browse files
[5.x] Allow custom render callback for overridden exceptions (#11408)
Co-authored-by: Jason Varga <[email protected]>
1 parent 6e9a16d commit 970ee2b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/Exceptions/Concerns/RendersHttpExceptions.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Statamic\Exceptions\Concerns;
44

5+
use Closure;
56
use Illuminate\Http\Request;
67
use Illuminate\Http\Response;
78
use Statamic\Facades\Cascade;
@@ -12,8 +13,14 @@
1213

1314
trait RendersHttpExceptions
1415
{
15-
public function render()
16+
private static ?Closure $renderCallback = null;
17+
18+
public function render(Request $request)
1619
{
20+
if (static::$renderCallback && ($response = Closure::fromCallable(static::$renderCallback)->call($this, $request))) {
21+
return $response;
22+
}
23+
1724
if (Statamic::isCpRoute()) {
1825
return response()->view('statamic::errors.'.$this->getStatusCode(), [], $this->getStatusCode());
1926
}
@@ -82,4 +89,9 @@ private function getCachedError(): ?Response
8289
? $cacher->getCachedPage($request)->toResponse($request)
8390
: null;
8491
}
92+
93+
public static function renderUsing(Closure $callback): void
94+
{
95+
static::$renderCallback = $callback;
96+
}
8597
}

0 commit comments

Comments
 (0)