From 288ff23f2b7ba798bc820fbccac0dc36648d04ba Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Sun, 7 Jul 2024 15:48:26 +0200 Subject: [PATCH] Improved InvalidToken handling for #1653 --- dev/Remote/AbstractFetch.js | 4 ++-- .../RainLoop/Exceptions/ClientException.php | 17 ++++++++++++++--- .../app/libraries/RainLoop/ServiceActions.php | 4 ++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/dev/Remote/AbstractFetch.js b/dev/Remote/AbstractFetch.js index 3925b31bd..087e8032f 100644 --- a/dev/Remote/AbstractFetch.js +++ b/dev/Remote/AbstractFetch.js @@ -10,9 +10,9 @@ const getURL = (add = '') => serverRequest('Json') + pString(add), checkResponseError = data => { const err = data ? data.ErrorCode : null; if (Notifications.InvalidToken === err) { - console.error(getNotification(err)); + console.error(getNotification(err) + ` (${data.ErrorMessageAdditional})`); // alert(getNotification(err)); - rl.logoutReload(); + setTimeout(rl.logoutReload, 5000); } else if ([ Notifications.AuthError, Notifications.ConnectionError, diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Exceptions/ClientException.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Exceptions/ClientException.php index 794403c46..6d7d824af 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Exceptions/ClientException.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Exceptions/ClientException.php @@ -15,9 +15,11 @@ class ClientException extends \RuntimeException public function __construct(int $iCode, ?\Throwable $oPrevious = null, string $sAdditionalMessage = '') { - parent::__construct(\RainLoop\Notifications::GetNotificationsMessage($iCode, $oPrevious), - $iCode, $oPrevious); - + parent::__construct( + \RainLoop\Notifications::GetNotificationsMessage($iCode, $oPrevious), + $iCode, + $oPrevious + ); $this->sAdditionalMessage = $sAdditionalMessage ?: ($oPrevious ? $oPrevious->getMessage() : ''); } @@ -25,4 +27,13 @@ class ClientException extends \RuntimeException { 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()}"; + } } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php index 444361b2b..217cc6a0c 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php @@ -149,9 +149,9 @@ class ServiceActions } catch (\Throwable $oException) { - \SnappyMail\Log::warning('SERVICE', "{$oException->getMessage()}\r\n{$oException->getTraceAsString()}"); + \SnappyMail\Log::warning('SERVICE', "{$oException}"); if ($e = $oException->getPrevious()) { - \SnappyMail\Log::warning('SERVICE', "- {$e->getMessage()} @ {$e->getFile()}#{$e->getLine()}"); + \SnappyMail\Log::warning('SERVICE', "- {$e}"); } $aResponse = $this->oActions->ExceptionResponse($oException);