]> BookStack Code Mirror - bookstack/blob - app/Exceptions/PrettyException.php
Moved NotifyException render work from handler to exception
[bookstack] / app / Exceptions / PrettyException.php
1 <?php namespace BookStack\Exceptions;
2
3 use Exception;
4 use Illuminate\Contracts\Support\Responsable;
5
6 class PrettyException extends Exception implements Responsable
7 {
8     /**
9      * @var ?string
10      */
11     protected $subtitle = null;
12
13     /**
14      * @var ?string
15      */
16     protected $details = null;
17
18     /**
19      * Render a response for when this exception occurs.
20      * @inheritdoc
21      */
22     public function toResponse($request)
23     {
24         $code = ($this->getCode() === 0) ? 500 : $this->getCode();
25         return response()->view('errors.' . $code, [
26             'message' => $this->getMessage(),
27             'subtitle' => $this->subtitle,
28             'details' => $this->details,
29         ], $code);
30     }
31
32     public function setSubtitle(string $subtitle): self
33     {
34         $this->subtitle = $subtitle;
35         return $this;
36     }
37
38     public function setDetails(string $details): self
39     {
40         $this->details = $details;
41         return $this;
42     }
43 }