From 8cd4a35c6f97678a0647f2c3b262df4ef11ca77c Mon Sep 17 00:00:00 2001 From: Edouard Marquez Date: Tue, 8 Aug 2023 22:26:36 +0200 Subject: [PATCH] feat: Registration/Password lost: better catch 504 errors from the server (#777) * Better catch 504 errors from the server * A simple character can change a lot of things ;) --- lib/src/model/sign_up_status.dart | 4 ++++ lib/src/open_food_api_client.dart | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/src/model/sign_up_status.dart b/lib/src/model/sign_up_status.dart index 9cb20c6b96..88760704d0 100644 --- a/lib/src/model/sign_up_status.dart +++ b/lib/src/model/sign_up_status.dart @@ -101,6 +101,7 @@ class SignUpStatus extends Status { SignUpStatusError.INVALID_PASSWORD, 'The user name must contain only unaccented letters, digits and dashes.': SignUpStatusError.INVALID_USERNAME, + '504 Gateway Time-out': SignUpStatusError.SERVER_BUSY, }; } @@ -122,6 +123,9 @@ enum SignUpStatusError { /// The password is incorrect (too short) INVALID_PASSWORD, + /// When the server is down (504 Gateway timeout) + SERVER_BUSY, + /// Generic error UNKNOWN, } diff --git a/lib/src/open_food_api_client.dart b/lib/src/open_food_api_client.dart index ea169754c3..c9c1d2bdee 100644 --- a/lib/src/open_food_api_client.dart +++ b/lib/src/open_food_api_client.dart @@ -1224,8 +1224,11 @@ class OpenFoodAPIClient { body: 'An email with a link to reset your password has been sent to the e-mail address associated with your account.', ); - } else { + } else if (status.status is int && status.status < 500) { return status.copyWith(status: 400); + } else { + /// Trigger real 5xx errors + return status; } }