Quick fix to propagate exeptions thrown by the RestSharp library. Pull request pending on RestSharp lib to prevent useless error's in case of dropped internet connection or other source of invalid server responses.

This commit is contained in:
Naliath 2013-04-19 08:44:26 +02:00
parent e6ba129aaa
commit cd6a372482
9 changed files with 51 additions and 15 deletions

View File

@ -62,8 +62,12 @@ namespace TMDbLib.Client
RestRequest req = new RestRequest("configuration");
IRestResponse<TMDbConfig> resp = _client.Get<TMDbConfig>(req);
if (resp.ResponseStatus != ResponseStatus.Completed)
throw new Exception("Error");
if (resp.ErrorException != null)
throw resp.ErrorException;
// TODO Create specific Exception type
if (resp.ResponseStatus != ResponseStatus.Completed || resp.Data == null)
throw new Exception("Unable to retrieve configuration");
// Store config
Config = resp.Data;

View File

@ -34,6 +34,8 @@ namespace TMDbLib.Client
req.DateFormat = "yyyy-MM-dd";
IRestResponse<Collection> resp = _client.Get<Collection>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
return resp.Data;
}
@ -48,6 +50,8 @@ namespace TMDbLib.Client
req.AddParameter("language", language);
IRestResponse<T> resp = _client.Get<T>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
return resp.Data;
}

View File

@ -26,6 +26,8 @@ namespace TMDbLib.Client
req.DateFormat = "yyyy-MM-dd";
IRestResponse<Company> resp = _client.Get<Company>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
return resp.Data;
}
@ -42,6 +44,8 @@ namespace TMDbLib.Client
req.AddParameter("language", language);
IRestResponse<T> resp = _client.Get<T>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
return resp.Data;
}

View File

@ -20,6 +20,8 @@ namespace TMDbLib.Client
req.AddParameter("language", language);
IRestResponse<GenreContainer> resp = _client.Get<GenreContainer>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
if (resp.Data == null)
return null;
@ -46,6 +48,8 @@ namespace TMDbLib.Client
req.AddParameter("include_all_movies", includeAllMovies.Value ? "true" : "false");
IRestResponse<SearchContainerWithId<MovieResult>> resp = _client.Get<SearchContainerWithId<MovieResult>>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
return resp.Data;
}

View File

@ -12,6 +12,8 @@ namespace TMDbLib.Client
req.AddUrlSegment("id", id.ToString());
IRestResponse<Keyword> resp = _client.Get<Keyword>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
return resp.Data;
}
@ -33,6 +35,8 @@ namespace TMDbLib.Client
req.AddParameter("page", page);
IRestResponse<SearchContainer<MovieResult>> resp = _client.Get<SearchContainer<MovieResult>>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
return resp.Data;
}

View File

@ -13,6 +13,8 @@ namespace TMDbLib.Client
req.DateFormat = "yyyy-MM-dd";
IRestResponse<List> resp = _client.Get<List>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
return resp.Data;
}

View File

@ -43,6 +43,8 @@ namespace TMDbLib.Client
req.AddParameter("append_to_response", appends);
IRestResponse<Movie> resp = _client.Get<Movie>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
// Patch up data, so that the end user won't notice that we share objects between request-types.
if (resp.Data != null)
@ -92,6 +94,8 @@ namespace TMDbLib.Client
req.AddParameter("end_date", endDate.Value.ToString("yyyy-MM-dd"));
IRestResponse<T> resp = _client.Get<T>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
return resp.Data;
}
@ -172,6 +176,8 @@ namespace TMDbLib.Client
{
RestRequest req = new RestRequest("movie/latest");
IRestResponse<Movie> resp = _client.Get<Movie>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
return resp.Data;
}
@ -207,6 +213,8 @@ namespace TMDbLib.Client
req.DateFormat = "yyyy-MM-dd";
IRestResponse<SearchContainer<MovieResult>> resp = _client.Get<SearchContainer<MovieResult>>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
return resp.Data;
}

View File

@ -27,6 +27,8 @@ namespace TMDbLib.Client
req.DateFormat = "yyyy-MM-dd";
IRestResponse<Person> resp = _client.Get<Person>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
// Patch up data, so that the end user won't notice that we share objects between request-types.
if (resp.Data != null)
@ -64,6 +66,8 @@ namespace TMDbLib.Client
req.AddParameter("endDate", endDate.Value.ToString("yyyy-MM-dd"));
IRestResponse<T> resp = _client.Get<T>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
return resp.Data;
}

View File

@ -26,6 +26,8 @@ namespace TMDbLib.Client
req.DateFormat = dateFormat;
IRestResponse<T> resp = _client.Get<T>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
return resp.Data;
}