]> BookStack Code Mirror - bookstack/blobdiff - app/Exceptions/NotifyException.php
feat(PageContent): set unique ids on nested headers
[bookstack] / app / Exceptions / NotifyException.php
index c9ff9975dca1e5dc9919313922234869a01df44e..8e748a21dc77ed17301610d6f6e1f877de4ac53e 100644 (file)
@@ -1,21 +1,38 @@
-<?php namespace Oxbow\Exceptions;
+<?php
 
+namespace BookStack\Exceptions;
 
-class NotifyException extends \Exception
-{
+use Exception;
+use Illuminate\Contracts\Support\Responsable;
 
+class NotifyException extends Exception implements Responsable
+{
     public $message;
     public $redirectLocation;
 
     /**
      * NotifyException constructor.
-     * @param string $message
-     * @param string    $redirectLocation
      */
-    public function __construct($message, $redirectLocation)
+    public function __construct(string $message, string $redirectLocation = '/')
     {
         $this->message = $message;
         $this->redirectLocation = $redirectLocation;
         parent::__construct();
     }
-}
\ No newline at end of file
+
+    /**
+     * 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);
+    }
+}