fix exception

This commit is contained in:
Yuri Kuznetsov
2020-09-04 12:50:18 +03:00
parent 3577dfda9f
commit 2c9a6aa456
+23 -7
View File
@@ -32,6 +32,8 @@ namespace Espo\Core\Api;
use Espo\Core\{
Api\Request,
Api\Response,
Exceptions\Conflict,
Exceptions\Error,
};
use Throwable;
@@ -156,13 +158,8 @@ class ErrorOutput
$response->setHeader('X-Status-Reason', $this->stripInvalidCharactersFromHeaderValue($message));
}
$exceptionBody = null;
if (method_exists($exception, 'getBody')) {
$exceptionBody = $exception->getBody();
}
if ($exceptionBody) {
$response->writeBody($exceptionBody);
if ($this->doesExceptionHaveBody($exception)) {
$response->writeBody($exception->getBody());
$toPrintBody = false;
}
@@ -182,6 +179,25 @@ class ErrorOutput
}
}
protected function doesExceptionHaveBody(Throwable $exception) : bool
{
if (
! $exception instanceof Error
&&
! $exception instanceof Conflict
) {
return false;
}
$exceptionBody = null;
if (method_exists($exception, 'getBody')) {
$exceptionBody = $exception->getBody();
}
return $exceptionBody !== null;
}
protected function getCodeDescription(int $statusCode) : ?string
{
if (isset($this->errorDescriptions[$statusCode])) {