mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 08:52:55 +08:00
Add API level support for error message and redirect during registration flow
This commit is contained in:
parent
5658c3a123
commit
a7327b02a2
@ -329,12 +329,35 @@ namespace osu.Game.Online.API
|
||||
{
|
||||
try
|
||||
{
|
||||
return JObject.Parse(req.GetResponseString().AsNonNull()).SelectToken("form_error", true).AsNonNull().ToObject<RegistrationRequest.RegistrationRequestErrors>();
|
||||
return JObject.Parse(req.GetResponseString().AsNonNull()).SelectToken(@"form_error", true).AsNonNull().ToObject<RegistrationRequest.RegistrationRequestErrors>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// if we couldn't deserialize the error message let's throw the original exception outwards.
|
||||
e.Rethrow();
|
||||
try
|
||||
{
|
||||
// attempt to parse a non-form error message
|
||||
var response = JObject.Parse(req.GetResponseString().AsNonNull());
|
||||
|
||||
string redirect = (string)response.SelectToken(@"url", true);
|
||||
string message = (string)response.SelectToken(@"error", false);
|
||||
|
||||
if (!string.IsNullOrEmpty(redirect))
|
||||
{
|
||||
return new RegistrationRequest.RegistrationRequestErrors
|
||||
{
|
||||
Redirect = redirect,
|
||||
Message = message,
|
||||
};
|
||||
}
|
||||
|
||||
// if we couldn't deserialize the error message let's throw the original exception outwards.
|
||||
e.Rethrow();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// if we couldn't deserialize the error message let's throw the original exception outwards.
|
||||
e.Rethrow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,16 @@ namespace osu.Game.Online.API
|
||||
|
||||
public class RegistrationRequestErrors
|
||||
{
|
||||
/// <summary>
|
||||
/// An optional error message.
|
||||
/// </summary>
|
||||
public string? Message;
|
||||
|
||||
/// <summary>
|
||||
/// An optional URL which the user should be directed towards to complete registration.
|
||||
/// </summary>
|
||||
public string? Redirect;
|
||||
|
||||
public UserErrors? User;
|
||||
|
||||
public class UserErrors
|
||||
|
Loading…
Reference in New Issue
Block a user