]> BookStack Code Mirror - bookstack/blob - app/Exceptions/PrettyException.php
Merge pull request #5625 from BookStackApp/avif_images
[bookstack] / app / Exceptions / PrettyException.php
1 <?php
2
3 namespace BookStack\Exceptions;
4
5 use Exception;
6 use Illuminate\Contracts\Support\Responsable;
7 use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
8
9 class PrettyException extends Exception implements Responsable, HttpExceptionInterface
10 {
11     protected ?string $subtitle = null;
12     protected ?string $details = null;
13
14     /**
15      * Render a response for when this exception occurs.
16      *
17      * {@inheritdoc}
18      */
19     public function toResponse($request)
20     {
21         $code = $this->getStatusCode();
22
23         return response()->view('errors.' . $code, [
24             'message'  => $this->getMessage(),
25             'subtitle' => $this->subtitle,
26             'details'  => $this->details,
27         ], $code);
28     }
29
30     public function setSubtitle(string $subtitle): self
31     {
32         $this->subtitle = $subtitle;
33
34         return $this;
35     }
36
37     public function setDetails(string $details): self
38     {
39         $this->details = $details;
40
41         return $this;
42     }
43
44     /**
45      * Get the desired HTTP status code for this exception.
46      */
47     public function getStatusCode(): int
48     {
49         return ($this->getCode() === 0) ? 500 : $this->getCode();
50     }
51
52     /**
53      * Get the desired HTTP headers for this exception.
54      */
55     public function getHeaders(): array
56     {
57         return [];
58     }
59 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.