mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 17:32:54 +08:00
Make AuthenticateWithLogin
throw instead of return a bool
success status
This commit is contained in:
parent
3d71576fbe
commit
5aaafce597
@ -6,7 +6,7 @@ using osu.Framework.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.AccountCreation
|
||||
namespace osu.Game.Graphics
|
||||
{
|
||||
public class ErrorTextFlowContainer : OsuTextFlowContainer
|
||||
{
|
@ -1,8 +1,10 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Net.Http;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.Bindables;
|
||||
|
||||
namespace osu.Game.Online.API
|
||||
@ -32,10 +34,10 @@ namespace osu.Game.Online.API
|
||||
this.endpoint = endpoint;
|
||||
}
|
||||
|
||||
internal bool AuthenticateWithLogin(string username, string password)
|
||||
internal void AuthenticateWithLogin(string username, string password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(username)) return false;
|
||||
if (string.IsNullOrEmpty(password)) return false;
|
||||
if (string.IsNullOrEmpty(username)) throw new ArgumentException("Missing username.");
|
||||
if (string.IsNullOrEmpty(password)) throw new ArgumentException("Missing password.");
|
||||
|
||||
using (var req = new AccessTokenRequestPassword(username, password)
|
||||
{
|
||||
@ -49,13 +51,27 @@ namespace osu.Game.Online.API
|
||||
{
|
||||
req.Perform();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Token.Value = null;
|
||||
|
||||
var throwableException = ex;
|
||||
|
||||
try
|
||||
{
|
||||
// attempt to decode a displayable error string.
|
||||
var error = JsonConvert.DeserializeObject<OAuthError>(req.GetResponseString() ?? string.Empty);
|
||||
if (error != null)
|
||||
throwableException = new APIException(error.Message, ex);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
throw throwableException;
|
||||
}
|
||||
|
||||
Token.Value = req.ResponseObject;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,5 +198,14 @@ namespace osu.Game.Online.API
|
||||
base.PrePerform();
|
||||
}
|
||||
}
|
||||
|
||||
private class OAuthError
|
||||
{
|
||||
[JsonProperty("error")]
|
||||
public string ErrorType { get; set; }
|
||||
|
||||
[JsonProperty("hint")]
|
||||
public string Message { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user