BookStack/app/Exceptions/NotifyException.php

49 lines
1 KiB
PHP
Raw Normal View History

2021-06-26 17:23:15 +02:00
<?php
namespace BookStack\Exceptions;
2015-09-04 18:16:58 +02:00
use Exception;
use Illuminate\Contracts\Support\Responsable;
2015-09-04 18:16:58 +02:00
class NotifyException extends Exception implements Responsable
{
2015-09-04 18:16:58 +02:00
public $message;
public $redirectLocation;
protected $status;
2015-09-04 18:16:58 +02:00
/**
* NotifyException constructor.
*/
public function __construct(string $message, string $redirectLocation = '/', int $status = 500)
2015-09-04 18:16:58 +02:00
{
$this->message = $message;
$this->redirectLocation = $redirectLocation;
$this->status = $status;
2015-09-04 18:16:58 +02:00
parent::__construct();
}
/**
* Get the desired status code for this exception.
*/
public function getStatus(): int
{
return $this->status;
}
/**
* Send the response for this type of exception.
2021-06-26 17:23:15 +02:00
*
* {@inheritdoc}
*/
public function toResponse($request)
{
$message = $this->getMessage();
if (!empty($message)) {
session()->flash('error', $message);
}
return redirect($this->redirectLocation);
}
}