diff --git a/src/Security/BpnAuthenticator.php b/src/Security/BpnAuthenticator.php index e2eeaa4..9d62d82 100644 --- a/src/Security/BpnAuthenticator.php +++ b/src/Security/BpnAuthenticator.php @@ -6,6 +6,8 @@ namespace App\Security; use App\BusProNet\ApiClient; use App\BusProNet\Exception\ApiClientException; +use App\BusProNet\Exception\ImmediateConnectionCloseException; +use App\BusProNet\Exception\TimeoutException; use App\BusProNet\Model\PersonalData; use App\Entity\User; use App\Htmx\HxRedirectResponse; @@ -63,11 +65,13 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent try { $response = $this->apiClient->getPersonalData($email, $password); } catch (ApiClientException $e) { - throw new CustomUserMessageAuthenticationException($e->getMessage()); + $message = $this->isConnectionError($e) ? + 'Der Server ist momentan nicht erreichbar. Bitte versuche es später erneut.' : $e->getMessage(); + throw new CustomUserMessageAuthenticationException($message); } if (false === $response instanceof PersonalData) { - throw new CustomUserMessageAuthenticationException('Der Login ist fehlgeschlagen :('); + throw new CustomUserMessageAuthenticationException('Benutzername oder Passwort ist nicht korrekt.'); } $csrfToken = $request->request->getString('_csrf_token'); @@ -87,7 +91,9 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent try { $crmAttributes = $this->apiClient->getCrmAttributes($email, $password); } catch (ApiClientException $e) { - throw new CustomUserMessageAuthenticationException($e->getMessage()); + $message = $this->isConnectionError($e) ? + 'Der Server ist momentan nicht erreichbar. Bitte versuche es später erneut. :(' : $e->getMessage(); + throw new CustomUserMessageAuthenticationException($message); } $roles = $crmAttributes->roles; @@ -134,4 +140,13 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent return new RedirectResponse($targetPath); } + + private function isConnectionError(ApiClientException $e): bool + { + if ($e instanceof TimeoutException || $e instanceof ImmediateConnectionCloseException) { + return true; + } + + return 'Unable to open socket' === $e->getMessage(); + } }