diff --git a/osu.Game/Online/API/APIAccess.cs b/osu.Game/Online/API/APIAccess.cs index 806a42a38b..b42c78e9cd 100644 --- a/osu.Game/Online/API/APIAccess.cs +++ b/osu.Game/Online/API/APIAccess.cs @@ -145,16 +145,14 @@ private void run() failureCount = 0; - var friendsReq = new GetFriendsRequest(); - friendsReq.Success += f => + fetchFriends(() => { - Friends.AddRange(f); - //we're connected! state.Value = APIState.Online; - }; - - handleRequest(friendsReq); + }, () => + { + state.Value = APIState.Failing; + }); }; if (!handleRequest(userReq)) @@ -255,6 +253,19 @@ public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, return null; } + private void fetchFriends(Action onSuccess, Action onFail) + { + var friendsReq = new GetFriendsRequest(); + friendsReq.Success += res => + { + Friends.AddRange(res); + onSuccess?.Invoke(); + }; + + if (!handleRequest(friendsReq)) + onFail?.Invoke(); + } + /// /// Handle a single API request. /// Ensures all exceptions are caught and dealt with correctly.