Add API level support for error message and redirect during registration flow

This commit is contained in:
Dean Herbert 2023-01-13 15:32:53 +09:00
parent 5658c3a123
commit a7327b02a2
2 changed files with 36 additions and 3 deletions

View File

@ -329,12 +329,35 @@ public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email,
{
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();
}
}
}

View File

@ -23,6 +23,16 @@ protected override void PrePerform()
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