From bdfe6b5e239caa43f2aa7174ece049a744d69a1c Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 28 Mar 2022 14:38:03 +0300 Subject: [PATCH] forbidden exception with body --- application/Espo/Core/Exceptions/Error.php | 4 +-- .../Espo/Core/Exceptions/Forbidden.php | 29 ++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/application/Espo/Core/Exceptions/Error.php b/application/Espo/Core/Exceptions/Error.php index d090835bd1..d51f8a12b8 100644 --- a/application/Espo/Core/Exceptions/Error.php +++ b/application/Espo/Core/Exceptions/Error.php @@ -43,9 +43,9 @@ class Error extends InternalServerError implements HasBody parent::__construct($message, $code, $previous); } - public static function createWithBody(string $reason, string $body): self + public static function createWithBody(string $message, string $body): self { - $exception = new static($reason); + $exception = new static($message); $exception->body = $body; diff --git a/application/Espo/Core/Exceptions/Forbidden.php b/application/Espo/Core/Exceptions/Forbidden.php index e2546b7fe3..0482c8f8f9 100644 --- a/application/Espo/Core/Exceptions/Forbidden.php +++ b/application/Espo/Core/Exceptions/Forbidden.php @@ -29,10 +29,37 @@ namespace Espo\Core\Exceptions; -class Forbidden extends \Exception +use Throwable; +use Exception; + +class Forbidden extends Exception implements HasBody { /** * @var int */ protected $code = 403; + + /** + * @var ?string + */ + private $body = null; + + final public function __construct(string $message = '', int $code = 0, Throwable $previous = null) + { + parent::__construct($message, $code, $previous); + } + + public static function createWithBody(string $message, string $body): self + { + $exception = new static($message); + + $exception->body = $body; + + return $exception; + } + + public function getBody(): ?string + { + return $this->body; + } }