Tweaked ApiRequest behavior on non-200 responses; think it was breaking login. :-"

pull/1199/head
smcpeck 8 years ago
parent 231a525109
commit ec973917b4

@ -66,10 +66,11 @@ namespace Ombi.Api
throw new ApiRequestException(message, response.ErrorException); throw new ApiRequestException(message, response.ErrorException);
} }
if (response.StatusCode != HttpStatusCode.OK) if (response.StatusCode == HttpStatusCode.OK)
return default(T);
else
return response.Data; return response.Data;
else
throw new Exception($"Got StatusCode={response.StatusCode} for {baseUri}.");
} }
public IRestResponse Execute(IRestRequest request, Uri baseUri) public IRestResponse Execute(IRestRequest request, Uri baseUri)
@ -92,10 +93,11 @@ namespace Ombi.Api
throw new ApiRequestException(message, response.ErrorException); throw new ApiRequestException(message, response.ErrorException);
} }
T result = default(T);
if (response.StatusCode == HttpStatusCode.OK) if (response.StatusCode == HttpStatusCode.OK)
result = DeserializeXml<T>(response.Content); return DeserializeXml<T>(response.Content);
return result; else
throw new Exception($"Got StatusCode={response.StatusCode} for {baseUri}.");
} }
public T ExecuteJson<T>(IRestRequest request, Uri baseUri) where T : new() public T ExecuteJson<T>(IRestRequest request, Uri baseUri) where T : new()
@ -111,10 +113,10 @@ namespace Ombi.Api
throw new ApiRequestException(message, response.ErrorException); throw new ApiRequestException(message, response.ErrorException);
} }
T result = default(T);
if (response.StatusCode == HttpStatusCode.OK) if (response.StatusCode == HttpStatusCode.OK)
result = JsonConvert.DeserializeObject<T>(response.Content, _settings); return JsonConvert.DeserializeObject<T>(response.Content, _settings);
return result; else
throw new Exception($"Got StatusCode={response.StatusCode} for {baseUri}.");
} }
private T DeserializeXml<T>(string input) private T DeserializeXml<T>(string input)

@ -373,7 +373,6 @@ namespace Ombi.UI.Modules
return Response.AsJson(new { result = false, message = Resources.UI.UserLogin_IncorrectUserPass }); return Response.AsJson(new { result = false, message = Resources.UI.UserLogin_IncorrectUserPass });
} }
var m = await AuthenticationSetup(userId, username, dateTimeOffset, loginGuid, isOwner, plexSettings.Enable, embySettings.Enable); var m = await AuthenticationSetup(userId, username, dateTimeOffset, loginGuid, isOwner, plexSettings.Enable, embySettings.Enable);
var landingSettings = await LandingPageSettings.GetSettingsAsync(); var landingSettings = await LandingPageSettings.GetSettingsAsync();
@ -397,7 +396,6 @@ namespace Ombi.UI.Modules
return CustomModuleExtensions.LoginAndRedirect(this, m.LoginGuid, null, retVal.ToString()); return CustomModuleExtensions.LoginAndRedirect(this, m.LoginGuid, null, retVal.ToString());
} }
return Response.AsJson(new { result = true, url = retVal.ToString() }); return Response.AsJson(new { result = true, url = retVal.ToString() });
} }
private async Task<Response> LoginUser() private async Task<Response> LoginUser()

Loading…
Cancel
Save