mirror of https://github.com/ppy/osu
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 @@ public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email,
|
||||||
{
|
{
|
||||||
try
|
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
|
catch
|
||||||
{
|
{
|
||||||
// if we couldn't deserialize the error message let's throw the original exception outwards.
|
try
|
||||||
e.Rethrow();
|
{
|
||||||
|
// 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 @@ protected override void PrePerform()
|
||||||
|
|
||||||
public class RegistrationRequestErrors
|
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 UserErrors? User;
|
||||||
|
|
||||||
public class UserErrors
|
public class UserErrors
|
||||||
|
|
Loading…
Reference in New Issue