mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 21:03:17 -07:00
Stop the Cachers from bombing out when the response from the 3rd party api returns an exception or invalid response. #171
This commit is contained in:
parent
54ab4854e6
commit
076a75b82f
12 changed files with 138 additions and 29 deletions
|
@ -25,7 +25,6 @@
|
|||
// ************************************************************************/
|
||||
#endregion
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
|
@ -34,14 +33,15 @@ using Newtonsoft.Json;
|
|||
using NLog;
|
||||
|
||||
using PlexRequests.Api.Interfaces;
|
||||
using PlexRequests.Helpers;
|
||||
using PlexRequests.Helpers.Exceptions;
|
||||
|
||||
using RestSharp;
|
||||
|
||||
namespace PlexRequests.Api
|
||||
{
|
||||
public class ApiRequest : IApiRequest
|
||||
{
|
||||
private JsonSerializerSettings Settings = new JsonSerializerSettings
|
||||
private readonly JsonSerializerSettings _settings = new JsonSerializerSettings
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
MissingMemberHandling = MissingMemberHandling.Ignore
|
||||
|
@ -66,7 +66,8 @@ namespace PlexRequests.Api
|
|||
if (response.ErrorException != null)
|
||||
{
|
||||
var message = "Error retrieving response. Check inner details for more info.";
|
||||
throw new ApplicationException(message, response.ErrorException);
|
||||
Log.Error(response.ErrorException);
|
||||
throw new ApiRequestException(message, response.ErrorException);
|
||||
}
|
||||
|
||||
return response.Data;
|
||||
|
@ -80,8 +81,9 @@ namespace PlexRequests.Api
|
|||
|
||||
if (response.ErrorException != null)
|
||||
{
|
||||
Log.Error(response.ErrorException);
|
||||
var message = "Error retrieving response. Check inner details for more info.";
|
||||
throw new ApplicationException(message, response.ErrorException);
|
||||
throw new ApiRequestException(message, response.ErrorException);
|
||||
}
|
||||
|
||||
return response;
|
||||
|
@ -95,8 +97,9 @@ namespace PlexRequests.Api
|
|||
|
||||
if (response.ErrorException != null)
|
||||
{
|
||||
Log.Error(response.ErrorException);
|
||||
var message = "Error retrieving response. Check inner details for more info.";
|
||||
throw new ApplicationException(message, response.ErrorException);
|
||||
throw new ApiRequestException(message, response.ErrorException);
|
||||
}
|
||||
|
||||
var result = DeserializeXml<T>(response.Content);
|
||||
|
@ -112,12 +115,13 @@ namespace PlexRequests.Api
|
|||
Log.Trace(response.Content);
|
||||
if (response.ErrorException != null)
|
||||
{
|
||||
Log.Error(response.ErrorException);
|
||||
var message = "Error retrieving response. Check inner details for more info.";
|
||||
throw new ApplicationException(message, response.ErrorException);
|
||||
throw new ApiRequestException(message, response.ErrorException);
|
||||
}
|
||||
|
||||
Log.Trace("Deserialzing Object");
|
||||
var json = JsonConvert.DeserializeObject<T>(response.Content, Settings);
|
||||
var json = JsonConvert.DeserializeObject<T>(response.Content, _settings);
|
||||
Log.Trace("Finished Deserialzing Object");
|
||||
|
||||
return json;
|
||||
|
@ -133,8 +137,9 @@ namespace PlexRequests.Api
|
|||
using (var sr = new StringReader(input))
|
||||
return (T)ser.Deserialize(sr);
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
catch (InvalidOperationException e)
|
||||
{
|
||||
Log.Error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue