auth error translatable exception message

This commit is contained in:
Yuri Kuznetsov
2022-12-27 14:37:34 +02:00
parent 3c4e33f0c5
commit a9e8d5b2b2
4 changed files with 31 additions and 2 deletions
+5
View File
@@ -30,6 +30,7 @@
namespace Espo\Core\Api;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\HasBody;
use Espo\Core\Exceptions\ServiceUnavailable;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Authentication\ConfigDataProvider;
@@ -233,6 +234,10 @@ class Auth
$response->setStatus($e->getCode());
if ($e->getBody()) {
$response->writeBody($e->getBody());
}
$this->log->notice("Auth: " . $e->getMessage());
return;
@@ -30,6 +30,7 @@
namespace Espo\Core\Authentication;
use Espo\Core\Authentication\Logout\Params as LogoutParams;
use Espo\Core\Exceptions\Error\Body;
use Espo\Repositories\UserData as UserDataRepository;
use Espo\Entities\Portal;
use Espo\Entities\User;
@@ -223,7 +224,12 @@ class Authentication
}
if (!$user->isAdmin() && $this->configDataProvider->isMaintenanceMode()) {
throw new ServiceUnavailable("Application is in maintenance mode.");
throw ServiceUnavailable::createWithBody(
"Application is in maintenance mod1e.",
Body::create()
->withMessageTranslation('maintenanceModeError', 'messages')
->encode()
);
}
if (!$this->processUserCheck($user, $authLogRecord)) {
@@ -29,8 +29,25 @@
namespace Espo\Core\Exceptions;
class ServiceUnavailable extends \Exception
class ServiceUnavailable extends \Exception implements HasBody
{
/** @var int */
protected $code = 503;
private ?string $body = null;
/**
* Create with a body (supposed to be sent to the frontend).
*/
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;
}
}
@@ -357,6 +357,7 @@
"massFollowZeroResult": "Nothing got followed",
"massUnfollowZeroResult": "Nothing got unfollowed",
"erasePersonalDataConfirmation": "Checked fields will be erased permanently. Are you sure?",
"maintenanceModeError": "The application currently is in maintenance mode.",
"maintenanceMode": "The application currently is in maintenance mode. Only admin users have access.\n\nMaintenance mode can be disabled at Administration → Settings.",
"resolveSaveConflict": "The record has been modified. You need to resolve the conflict before you can save the record.",
"massPrintPdfMaxCountError": "Can't print more that {maxCount} records.",