mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Refactor exception handling by using interface
This commit is contained in:
@ -4,8 +4,9 @@ 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
|
||||
@ -17,6 +18,11 @@ class PrettyException extends Exception implements Responsable
|
||||
*/
|
||||
protected $details = null;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $headers = [];
|
||||
|
||||
/**
|
||||
* Render a response for when this exception occurs.
|
||||
*
|
||||
@ -24,7 +30,7 @@ class PrettyException extends Exception implements Responsable
|
||||
*/
|
||||
public function toResponse($request)
|
||||
{
|
||||
$code = ($this->getCode() === 0) ? 500 : $this->getCode();
|
||||
$code = $this->getStatusCode();
|
||||
|
||||
return response()->view('errors.' . $code, [
|
||||
'message' => $this->getMessage(),
|
||||
@ -46,4 +52,30 @@ class PrettyException extends Exception implements Responsable
|
||||
|
||||
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.
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function getHeaders(): array
|
||||
{
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the desired HTTP headers for this exception.
|
||||
* @param array<mixed> $headers
|
||||
*/
|
||||
public function setHeaders(array $headers): void
|
||||
{
|
||||
$this->headers = $headers;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user