Skip to content

Commit

Permalink
feat: Registration/Password lost: better catch 504 errors from the se…
Browse files Browse the repository at this point in the history
…rver (#777)

* Better catch 504 errors from the server

* A simple character can change a lot of things ;)
  • Loading branch information
g123k authored Aug 8, 2023
1 parent 8792510 commit 8cd4a35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/src/model/sign_up_status.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand All @@ -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,
}
5 changes: 4 additions & 1 deletion lib/src/open_food_api_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 8cd4a35

Please sign in to comment.