]> BookStack Code Mirror - bookstack/blobdiff - app/Exceptions/NotifyException.php
Started work on details/summary blocks
[bookstack] / app / Exceptions / NotifyException.php
index 4f810596099cf2132093677b571ce40bf44a5aa8..8e748a21dc77ed17301610d6f6e1f877de4ac53e 100644 (file)
@@ -1,18 +1,38 @@
-<?php namespace BookStack\Exceptions;
+<?php
 
-class NotifyException extends \Exception
-{
+namespace BookStack\Exceptions;
+
+use Exception;
+use Illuminate\Contracts\Support\Responsable;
 
+class NotifyException extends Exception implements Responsable
+{
     public $message;
     public $redirectLocation;
 
     /**
      * NotifyException constructor.
      */
-    public function __construct(string $message, string $redirectLocation = "/")
+    public function __construct(string $message, string $redirectLocation = '/')
     {
         $this->message = $message;
         $this->redirectLocation = $redirectLocation;
         parent::__construct();
     }
+
+    /**
+     * Send the response for this type of exception.
+     *
+     * {@inheritdoc}
+     */
+    public function toResponse($request)
+    {
+        $message = $this->getMessage();
+
+        if (!empty($message)) {
+            session()->flash('error', $message);
+        }
+
+        return redirect($this->redirectLocation);
+    }
 }