Browse Source

http exception handling

Krzysztof Krysiński 4 months ago
parent
commit
e1bc81b054

+ 2 - 1
src/PixiEditor/Data/Localization/Languages/en.json

@@ -1031,5 +1031,6 @@
   "SESSION_NOT_FOUND": "Session not found, try logging in again",
   "INTERNAL_SERVER_ERROR": "There was an internal server error. Please try again later.",
   "TOO_MANY_REQUESTS": "Too many requests. Try again in {0} seconds.",
-  "SESSION_EXPIRED": "Session expired. Please log in again."
+  "SESSION_EXPIRED": "Session expired. Please log in again.",
+  "CONNECTION_ERROR": "Connection error. Please check your internet connection."
 }

+ 28 - 1
src/PixiEditor/ViewModels/SubViewModels/UserViewModel.cs

@@ -102,6 +102,10 @@ internal class UserViewModel : SubViewModel<ViewModelMain>
         {
             LastError = new LocalizedString(authException.Message);
         }
+        catch (HttpRequestException httpRequestException)
+        {
+            LastError = new LocalizedString("CONNECTION_ERROR");
+        }
     }
 
     public async Task ResendActivation()
@@ -132,6 +136,10 @@ internal class UserViewModel : SubViewModel<ViewModelMain>
         {
             LastError = new LocalizedString(authException.Message);
         }
+        catch (HttpRequestException httpRequestException)
+        {
+            LastError = new LocalizedString("CONNECTION_ERROR");
+        }
     }
 
     private void RunTimeoutTimers(double timeLeft)
@@ -190,6 +198,10 @@ internal class UserViewModel : SubViewModel<ViewModelMain>
         {
             LastError = new LocalizedString(authException.Message);
         }
+        catch (HttpRequestException httpRequestException)
+        {
+            LastError = new LocalizedString("CONNECTION_ERROR");
+        }
 
         return false;
     }
@@ -228,6 +240,10 @@ internal class UserViewModel : SubViewModel<ViewModelMain>
         {
             LastError = new LocalizedString(authException.Message);
         }
+        catch (HttpRequestException httpRequestException)
+        {
+            LastError = new LocalizedString("CONNECTION_ERROR");
+        }
 
         return false;
     }
@@ -248,7 +264,18 @@ internal class UserViewModel : SubViewModel<ViewModelMain>
 
         if (!apiValid) return;
 
-        await PixiAuthClient.Logout(sessionId.Value, sessionToken);
+        try
+        {
+            await PixiAuthClient.Logout(sessionId.Value, sessionToken);
+        }
+        catch (PixiAuthException authException)
+        {
+
+        }
+        catch (HttpRequestException httpRequestException)
+        {
+
+        }
     }
 
     public async Task SaveUserInfo()