mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 20:33:11 +08:00
Merge pull request #2860 from peppy/fix-unauthorized-request
Fix API getting stuck in an endless loop under a certain unauthorized scenario
This commit is contained in:
commit
73994482d5
@ -148,7 +148,7 @@ namespace osu.Game.Online.API
|
|||||||
// The Success callback event is fired on the main thread, so we should wait for that to run before proceeding.
|
// The Success callback event is fired on the main thread, so we should wait for that to run before proceeding.
|
||||||
// Without this, we will end up circulating this Connecting loop multiple times and queueing up many web requests
|
// Without this, we will end up circulating this Connecting loop multiple times and queueing up many web requests
|
||||||
// before actually going online.
|
// before actually going online.
|
||||||
while (State != APIState.Online)
|
while (State > APIState.Offline && State < APIState.Online)
|
||||||
Thread.Sleep(500);
|
Thread.Sleep(500);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -158,7 +158,6 @@ namespace osu.Game.Online.API
|
|||||||
if (authentication.RequestAccessToken() == null)
|
if (authentication.RequestAccessToken() == null)
|
||||||
{
|
{
|
||||||
Logout(false);
|
Logout(false);
|
||||||
State = APIState.Offline;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,6 +207,14 @@ namespace osu.Game.Online.API
|
|||||||
{
|
{
|
||||||
HttpStatusCode statusCode = (we.Response as HttpWebResponse)?.StatusCode ?? (we.Status == WebExceptionStatus.UnknownError ? HttpStatusCode.NotAcceptable : HttpStatusCode.RequestTimeout);
|
HttpStatusCode statusCode = (we.Response as HttpWebResponse)?.StatusCode ?? (we.Status == WebExceptionStatus.UnknownError ? HttpStatusCode.NotAcceptable : HttpStatusCode.RequestTimeout);
|
||||||
|
|
||||||
|
// special cases for un-typed but useful message responses.
|
||||||
|
switch (we.Message)
|
||||||
|
{
|
||||||
|
case "Unauthorized":
|
||||||
|
statusCode = HttpStatusCode.Unauthorized;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
switch (statusCode)
|
switch (statusCode)
|
||||||
{
|
{
|
||||||
case HttpStatusCode.Unauthorized:
|
case HttpStatusCode.Unauthorized:
|
||||||
@ -292,6 +299,7 @@ namespace osu.Game.Online.API
|
|||||||
password = null;
|
password = null;
|
||||||
authentication.Clear();
|
authentication.Clear();
|
||||||
LocalUser.Value = createGuestUser();
|
LocalUser.Value = createGuestUser();
|
||||||
|
State = APIState.Offline;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static User createGuestUser() => new User
|
private static User createGuestUser() => new User
|
||||||
|
Loading…
Reference in New Issue
Block a user