Browse Source

Merge pull request #1206 from PixiEditor/better-40x-handling

Catch all cases for 40x status code
Krzysztof Krysiński 1 week ago
parent
commit
fb53a52686
1 changed files with 28 additions and 31 deletions
  1. 28 31
      src/PixiEditor.PixiAuth/PixiAuthClient.cs

+ 28 - 31
src/PixiEditor.PixiAuth/PixiAuthClient.cs

@@ -42,10 +42,6 @@ public class PixiAuthClient
                 return sessionId;
                 return sessionId;
             }
             }
         }
         }
-        else if (response.StatusCode == HttpStatusCode.BadRequest)
-        {
-            throw new BadRequestException(await response.Content.ReadAsStringAsync());
-        }
         else if (response.StatusCode >= HttpStatusCode.InternalServerError)
         else if (response.StatusCode >= HttpStatusCode.InternalServerError)
         {
         {
             throw new InternalServerErrorException("INTERNAL_SERVER_ERROR");
             throw new InternalServerErrorException("INTERNAL_SERVER_ERROR");
@@ -68,6 +64,10 @@ public class PixiAuthClient
         {
         {
             throw new ForbiddenException("FORBIDDEN");
             throw new ForbiddenException("FORBIDDEN");
         }
         }
+        else if (response.StatusCode >= HttpStatusCode.BadRequest)
+        {
+            throw new BadRequestException(await response.Content.ReadAsStringAsync());
+        }
 
 
         return null;
         return null;
     }
     }
@@ -97,10 +97,6 @@ public class PixiAuthClient
                 return (token, expirationDate);
                 return (token, expirationDate);
             }
             }
         }
         }
-        else if (response.StatusCode == HttpStatusCode.BadRequest)
-        {
-            throw new BadRequestException(await response.Content.ReadAsStringAsync());
-        }
         else if (response.StatusCode >= HttpStatusCode.InternalServerError)
         else if (response.StatusCode >= HttpStatusCode.InternalServerError)
         {
         {
             throw new InternalServerErrorException("INTERNAL_SERVER_ERROR");
             throw new InternalServerErrorException("INTERNAL_SERVER_ERROR");
@@ -113,6 +109,10 @@ public class PixiAuthClient
         {
         {
             throw new ForbiddenException("FORBIDDEN");
             throw new ForbiddenException("FORBIDDEN");
         }
         }
+        else if (response.StatusCode >= HttpStatusCode.BadRequest)
+        {
+            throw new BadRequestException(await response.Content.ReadAsStringAsync());
+        }
 
 
         return (null, null);
         return (null, null);
     }
     }
@@ -157,18 +157,14 @@ public class PixiAuthClient
                 return (token, expirationDate);
                 return (token, expirationDate);
             }
             }
         }
         }
-        else if (response.StatusCode == HttpStatusCode.Forbidden)
-        {
-            throw new ForbiddenException("SESSION_NOT_VALID");
-        }
-        else if (response.StatusCode == HttpStatusCode.BadRequest)
-        {
-            throw new BadRequestException(await response.Content.ReadAsStringAsync());
-        }
         else if ((int)response.StatusCode >= 500)
         else if ((int)response.StatusCode >= 500)
         {
         {
             throw new InternalServerErrorException("INTERNAL_SERVER_ERROR");
             throw new InternalServerErrorException("INTERNAL_SERVER_ERROR");
         }
         }
+        else if (response.StatusCode == HttpStatusCode.Forbidden)
+        {
+            throw new ForbiddenException("SESSION_NOT_VALID");
+        }
         else if (response.StatusCode == HttpStatusCode.Unauthorized)
         else if (response.StatusCode == HttpStatusCode.Unauthorized)
         {
         {
             throw new UnauthorizedAccessException("UNAUTHORIZED");
             throw new UnauthorizedAccessException("UNAUTHORIZED");
@@ -177,6 +173,10 @@ public class PixiAuthClient
         {
         {
             throw new ForbiddenException("FORBIDDEN");
             throw new ForbiddenException("FORBIDDEN");
         }
         }
+        else if (response.StatusCode >= HttpStatusCode.BadRequest)
+        {
+            throw new BadRequestException(await response.Content.ReadAsStringAsync());
+        }
 
 
         return (null, null);
         return (null, null);
     }
     }
@@ -222,15 +222,14 @@ public class PixiAuthClient
 
 
         var response = await httpClient.SendAsync(request);
         var response = await httpClient.SendAsync(request);
 
 
-        if (response.StatusCode == HttpStatusCode.BadRequest)
-        {
-            throw new BadRequestException(await response.Content.ReadAsStringAsync());
-        }
-
         if (response.StatusCode >= HttpStatusCode.InternalServerError)
         if (response.StatusCode >= HttpStatusCode.InternalServerError)
         {
         {
             throw new InternalServerErrorException("INTERNAL_SERVER_ERROR");
             throw new InternalServerErrorException("INTERNAL_SERVER_ERROR");
         }
         }
+        if (response.StatusCode >= HttpStatusCode.BadRequest)
+        {
+            throw new BadRequestException(await response.Content.ReadAsStringAsync());
+        }
 
 
         if (response.StatusCode == HttpStatusCode.OK)
         if (response.StatusCode == HttpStatusCode.OK)
         {
         {
@@ -256,15 +255,14 @@ public class PixiAuthClient
 
 
         var response = await httpClient.SendAsync(request);
         var response = await httpClient.SendAsync(request);
 
 
-        if (response.StatusCode == HttpStatusCode.BadRequest)
-        {
-            throw new BadRequestException(await response.Content.ReadAsStringAsync());
-        }
-
         if (response.StatusCode >= HttpStatusCode.InternalServerError)
         if (response.StatusCode >= HttpStatusCode.InternalServerError)
         {
         {
             throw new InternalServerErrorException("INTERNAL_SERVER_ERROR");
             throw new InternalServerErrorException("INTERNAL_SERVER_ERROR");
         }
         }
+        if (response.StatusCode >= HttpStatusCode.BadRequest)
+        {
+            throw new BadRequestException(await response.Content.ReadAsStringAsync());
+        }
 
 
         if (response.StatusCode == HttpStatusCode.OK)
         if (response.StatusCode == HttpStatusCode.OK)
         {
         {
@@ -294,15 +292,14 @@ public class PixiAuthClient
 
 
         var response = await httpClient.SendAsync(request);
         var response = await httpClient.SendAsync(request);
 
 
-        if (response.StatusCode == HttpStatusCode.BadRequest)
-        {
-            throw new BadRequestException(await response.Content.ReadAsStringAsync());
-        }
-
         if (response.StatusCode >= HttpStatusCode.InternalServerError)
         if (response.StatusCode >= HttpStatusCode.InternalServerError)
         {
         {
             throw new InternalServerErrorException("INTERNAL_SERVER_ERROR");
             throw new InternalServerErrorException("INTERNAL_SERVER_ERROR");
         }
         }
+        if (response.StatusCode >= HttpStatusCode.BadRequest)
+        {
+            throw new BadRequestException(await response.Content.ReadAsStringAsync());
+        }
 
 
         if (response.StatusCode == HttpStatusCode.OK)
         if (response.StatusCode == HttpStatusCode.OK)
         {
         {