-
-
Notifications
You must be signed in to change notification settings - Fork 541
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb101ff
commit 104104f
Showing
3 changed files
with
52 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Statamic\Exceptions\Concerns; | ||
|
||
use Statamic\Facades\Cascade; | ||
use Statamic\Statamic; | ||
use Statamic\View\View; | ||
|
||
trait RendersHttpExceptions | ||
{ | ||
public function render() | ||
{ | ||
if (Statamic::isCpRoute()) { | ||
return response()->view('statamic::errors.'.$this->getStatusCode(), [], $this->getStatusCode()); | ||
} | ||
|
||
if (view()->exists('errors.'.$this->getStatusCode())) { | ||
return response($this->contents(), $this->getStatusCode()); | ||
} | ||
} | ||
|
||
protected function contents() | ||
{ | ||
Cascade::hydrated(function ($cascade) { | ||
$cascade->set('response_code', $this->getStatusCode()); | ||
}); | ||
|
||
return app(View::class) | ||
->template('errors.'.$this->getStatusCode()) | ||
->layout($this->layout()) | ||
->render(); | ||
} | ||
|
||
protected function layout() | ||
{ | ||
$layouts = collect([ | ||
'errors.layout', | ||
'layouts.layout', | ||
'layout', | ||
'statamic::blank', | ||
]); | ||
|
||
return $layouts->filter()->first(function ($layout) { | ||
return view()->exists($layout); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters