]> BookStack Code Mirror - bookstack/blob - app/Exceptions/NotifyException.php
Added user API examples
[bookstack] / app / Exceptions / NotifyException.php
1 <?php
2
3 namespace BookStack\Exceptions;
4
5 use Exception;
6 use Illuminate\Contracts\Support\Responsable;
7
8 class NotifyException extends Exception implements Responsable
9 {
10     public $message;
11     public $redirectLocation;
12     protected $status;
13
14     /**
15      * NotifyException constructor.
16      */
17     public function __construct(string $message, string $redirectLocation = '/', int $status = 500)
18     {
19         $this->message = $message;
20         $this->redirectLocation = $redirectLocation;
21         $this->status = $status;
22         parent::__construct();
23     }
24
25     /**
26      * Get the desired status code for this exception.
27      */
28     public function getStatus(): int
29     {
30         return $this->status;
31     }
32
33     /**
34      * Send the response for this type of exception.
35      *
36      * {@inheritdoc}
37      */
38     public function toResponse($request)
39     {
40         $message = $this->getMessage();
41
42         if (!empty($message)) {
43             session()->flash('error', $message);
44         }
45
46         return redirect($this->redirectLocation);
47     }
48 }