diff --git a/ChessCubing.App/Components/SiteMenu.razor b/ChessCubing.App/Components/SiteMenu.razor index 0c7c21f..10296fe 100644 --- a/ChessCubing.App/Components/SiteMenu.razor +++ b/ChessCubing.App/Components/SiteMenu.razor @@ -1,4 +1,5 @@ @using System.ComponentModel.DataAnnotations +@using System.Net @using System.Net.Http.Json @using System.Security.Claims @using ChessCubing.App.Models.Auth @@ -270,6 +271,12 @@ try { + if (!await EnsureAuthServiceReadyAsync()) + { + FormError = "Le service d'authentification demarre encore. Reessaie dans quelques secondes."; + return; + } + var response = await Http.PostAsJsonAsync(endpoint, payload); if (!response.IsSuccessStatusCode) { @@ -292,6 +299,14 @@ ResetForms(); await RefreshAuthenticationStateAsync(); } + catch (HttpRequestException) + { + FormError = "Le service d'authentification est temporairement indisponible. Reessaie dans quelques secondes."; + } + catch (TaskCanceledException) + { + FormError = "La reponse du service d'authentification a pris trop de temps. Reessaie dans quelques secondes."; + } catch { FormError = fallbackMessage; @@ -396,7 +411,27 @@ { } - return fallbackMessage; + return response.StatusCode switch + { + HttpStatusCode.BadGateway or HttpStatusCode.ServiceUnavailable or HttpStatusCode.GatewayTimeout + => "Le service d'authentification demarre encore. Reessaie dans quelques secondes.", + HttpStatusCode.Conflict + => "Ce nom d'utilisateur ou cet email existe deja.", + _ => fallbackMessage, + }; + } + + private async Task EnsureAuthServiceReadyAsync() + { + try + { + using var response = await Http.GetAsync("api/health"); + return response.IsSuccessStatusCode; + } + catch + { + return false; + } } private static string BoolString(bool value)