Improved InvalidToken handling for #1653

This commit is contained in:
the-djmaze 2024-07-07 15:48:26 +02:00
parent 7f64dee54b
commit 288ff23f2b
3 changed files with 18 additions and 7 deletions

View file

@ -10,9 +10,9 @@ const getURL = (add = '') => serverRequest('Json') + pString(add),
checkResponseError = data => { checkResponseError = data => {
const err = data ? data.ErrorCode : null; const err = data ? data.ErrorCode : null;
if (Notifications.InvalidToken === err) { if (Notifications.InvalidToken === err) {
console.error(getNotification(err)); console.error(getNotification(err) + ` (${data.ErrorMessageAdditional})`);
// alert(getNotification(err)); // alert(getNotification(err));
rl.logoutReload(); setTimeout(rl.logoutReload, 5000);
} else if ([ } else if ([
Notifications.AuthError, Notifications.AuthError,
Notifications.ConnectionError, Notifications.ConnectionError,

View file

@ -15,9 +15,11 @@ class ClientException extends \RuntimeException
public function __construct(int $iCode, ?\Throwable $oPrevious = null, string $sAdditionalMessage = '') public function __construct(int $iCode, ?\Throwable $oPrevious = null, string $sAdditionalMessage = '')
{ {
parent::__construct(\RainLoop\Notifications::GetNotificationsMessage($iCode, $oPrevious), parent::__construct(
$iCode, $oPrevious); \RainLoop\Notifications::GetNotificationsMessage($iCode, $oPrevious),
$iCode,
$oPrevious
);
$this->sAdditionalMessage = $sAdditionalMessage ?: ($oPrevious ? $oPrevious->getMessage() : ''); $this->sAdditionalMessage = $sAdditionalMessage ?: ($oPrevious ? $oPrevious->getMessage() : '');
} }
@ -25,4 +27,13 @@ class ClientException extends \RuntimeException
{ {
return $this->sAdditionalMessage; return $this->sAdditionalMessage;
} }
public function __toString() : string
{
$message = $this->getMessage();
if ($this->sAdditionalMessage) {
$message .= " ({$this->sAdditionalMessage})";
}
return "{$message}\r\n{$this->getFile()}#{$this->getLine()}\r\n{$this->getTraceAsString()}";
}
} }

View file

@ -149,9 +149,9 @@ class ServiceActions
} }
catch (\Throwable $oException) catch (\Throwable $oException)
{ {
\SnappyMail\Log::warning('SERVICE', "{$oException->getMessage()}\r\n{$oException->getTraceAsString()}"); \SnappyMail\Log::warning('SERVICE', "{$oException}");
if ($e = $oException->getPrevious()) { if ($e = $oException->getPrevious()) {
\SnappyMail\Log::warning('SERVICE', "- {$e->getMessage()} @ {$e->getFile()}#{$e->getLine()}"); \SnappyMail\Log::warning('SERVICE', "- {$e}");
} }
$aResponse = $this->oActions->ExceptionResponse($oException); $aResponse = $this->oActions->ExceptionResponse($oException);