]> BookStack Code Mirror - bookstack/blobdiff - app/Exceptions/PrettyException.php
Opensearch: Fixed XML declaration when php short tags enabled
[bookstack] / app / Exceptions / PrettyException.php
index 8ed135de7c11f0e3c0b89a3845e4dc4d77cfca1c..606085231f77411e467b2395437373d7e5bf04d6 100644 (file)
@@ -1,43 +1,59 @@
-<?php namespace BookStack\Exceptions;
+<?php
+
+namespace BookStack\Exceptions;
 
 use Exception;
 use Illuminate\Contracts\Support\Responsable;
+use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
 
-class PrettyException extends Exception implements Responsable
+class PrettyException extends Exception implements Responsable, HttpExceptionInterface
 {
-    /**
-     * @var ?string
-     */
-    protected $subtitle = null;
-
-    /**
-     * @var ?string
-     */
-    protected $details = null;
+    protected ?string $subtitle = null;
+    protected ?string $details = null;
 
     /**
      * Render a response for when this exception occurs.
-     * @inheritdoc
+     *
+     * {@inheritdoc}
      */
     public function toResponse($request)
     {
-        $code = ($this->getCode() === 0) ? 500 : $this->getCode();
+        $code = $this->getStatusCode();
+
         return response()->view('errors.' . $code, [
-            'message' => $this->getMessage(),
+            'message'  => $this->getMessage(),
             'subtitle' => $this->subtitle,
-            'details' => $this->details,
+            'details'  => $this->details,
         ], $code);
     }
 
     public function setSubtitle(string $subtitle): self
     {
         $this->subtitle = $subtitle;
+
         return $this;
     }
 
     public function setDetails(string $details): self
     {
         $this->details = $details;
+
         return $this;
     }
+
+    /**
+     * Get the desired HTTP status code for this exception.
+     */
+    public function getStatusCode(): int
+    {
+        return ($this->getCode() === 0) ? 500 : $this->getCode();
+    }
+
+    /**
+     * Get the desired HTTP headers for this exception.
+     */
+    public function getHeaders(): array
+    {
+        return [];
+    }
 }