From 94ffa77f908899d26c842c716eb0f062badb216f Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 6 Nov 2023 12:46:42 +0200 Subject: [PATCH] error body message --- .../Espo/Core/Authentication/Authentication.php | 7 ++++--- application/Espo/Core/Exceptions/Error/Body.php | 13 +++++++++++++ client/src/app.js | 12 ++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/application/Espo/Core/Authentication/Authentication.php b/application/Espo/Core/Authentication/Authentication.php index b6d9dca216..eccda910bd 100644 --- a/application/Espo/Core/Authentication/Authentication.php +++ b/application/Espo/Core/Authentication/Authentication.php @@ -32,6 +32,7 @@ namespace Espo\Core\Authentication; use Espo\Core\Exceptions\Forbidden; use Espo\Core\Exceptions\NotFound; +use Espo\Core\Utils\Language; use Espo\Repositories\UserData as UserDataRepository; use Espo\Entities\Portal; use Espo\Entities\User; @@ -87,7 +88,8 @@ class Authentication private Log $log, private LogoutFactory $logoutFactory, private MethodProvider $methodProvider, - private Util $util + private Util $util, + private Language $language ) {} /** @@ -204,8 +206,7 @@ class Authentication throw ServiceUnavailable::createWithBody( "Application is in maintenance mod1e.", Body::create() - ->withMessageTranslation('maintenanceModeError', 'messages') - ->encode() + ->withMessage($this->language->translateLabel('maintenanceModeError', 'messages')) ); } diff --git a/application/Espo/Core/Exceptions/Error/Body.php b/application/Espo/Core/Exceptions/Error/Body.php index 6b4e2684c2..832c4d85c6 100644 --- a/application/Espo/Core/Exceptions/Error/Body.php +++ b/application/Espo/Core/Exceptions/Error/Body.php @@ -41,6 +41,7 @@ class Body private ?string $messageTranslationScope = null; /** @var ?array */ private ?array $messageTranslationData = null; + private ?string $message = null; public static function create(): self { @@ -63,6 +64,14 @@ class Body return $obj; } + public function withMessage(string $message): self + { + $obj = clone $this; + $obj->message = $message; + + return $obj; + } + public function encode(): string { $data = (object) []; @@ -77,6 +86,10 @@ class Body ]; } + if ($this->message) { + $data->message = $this->message; + } + return Json::encode($data); } } diff --git a/client/src/app.js b/client/src/app.js index 6ae321aafa..204a9414e7 100644 --- a/client/src/app.js +++ b/client/src/app.js @@ -1308,6 +1308,18 @@ class App { isMessageDone = true; } + + if ( + !isMessageDone && + data && + 'message'in data && + data.message + ) { + obj.msg += '\n' + data.message; + obj.closeButton = true; + + isMessageDone = true; + } } if (!isMessageDone) {