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

@ -60,10 +60,14 @@ namespace TMDbLib.Client
public void GetConfig()
{
RestRequest req = new RestRequest("configuration");
IRestResponse<TMDbConfig> resp = _client.Get<TMDbConfig>(req);
IRestResponse<TMDbConfig> resp = _client.Get<TMDbConfig>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
if (resp.ResponseStatus != ResponseStatus.Completed)
throw new Exception("Error");
// 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

@ -33,7 +33,9 @@ namespace TMDbLib.Client
req.DateFormat = "yyyy-MM-dd";
IRestResponse<Collection> resp = _client.Get<Collection>(req);
IRestResponse<Collection> resp = _client.Get<Collection>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
return resp.Data;
}
@ -47,7 +49,9 @@ namespace TMDbLib.Client
if (language != null)
req.AddParameter("language", language);
IRestResponse<T> resp = _client.Get<T>(req);
IRestResponse<T> resp = _client.Get<T>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
return resp.Data;
}

View File

@ -25,7 +25,9 @@ namespace TMDbLib.Client
req.DateFormat = "yyyy-MM-dd";
IRestResponse<Company> resp = _client.Get<Company>(req);
IRestResponse<Company> resp = _client.Get<Company>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
return resp.Data;
}
@ -41,7 +43,9 @@ namespace TMDbLib.Client
if (language != null)
req.AddParameter("language", language);
IRestResponse<T> resp = _client.Get<T>(req);
IRestResponse<T> resp = _client.Get<T>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
return resp.Data;
}

View File

@ -19,7 +19,9 @@ namespace TMDbLib.Client
if (language != null)
req.AddParameter("language", language);
IRestResponse<GenreContainer> resp = _client.Get<GenreContainer>(req);
IRestResponse<GenreContainer> resp = _client.Get<GenreContainer>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
if (resp.Data == null)
return null;
@ -45,7 +47,9 @@ namespace TMDbLib.Client
if (includeAllMovies.HasValue)
req.AddParameter("include_all_movies", includeAllMovies.Value ? "true" : "false");
IRestResponse<SearchContainerWithId<MovieResult>> resp = _client.Get<SearchContainerWithId<MovieResult>>(req);
IRestResponse<SearchContainerWithId<MovieResult>> resp = _client.Get<SearchContainerWithId<MovieResult>>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
return resp.Data;
}

View File

@ -11,7 +11,9 @@ namespace TMDbLib.Client
RestRequest req = new RestRequest("keyword/{id}");
req.AddUrlSegment("id", id.ToString());
IRestResponse<Keyword> resp = _client.Get<Keyword>(req);
IRestResponse<Keyword> resp = _client.Get<Keyword>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
return resp.Data;
}
@ -32,7 +34,9 @@ namespace TMDbLib.Client
if (page >= 1)
req.AddParameter("page", page);
IRestResponse<SearchContainer<MovieResult>> resp = _client.Get<SearchContainer<MovieResult>>(req);
IRestResponse<SearchContainer<MovieResult>> resp = _client.Get<SearchContainer<MovieResult>>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
return resp.Data;
}

View File

@ -12,7 +12,9 @@ namespace TMDbLib.Client
req.DateFormat = "yyyy-MM-dd";
IRestResponse<List> resp = _client.Get<List>(req);
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

@ -26,7 +26,9 @@ namespace TMDbLib.Client
req.DateFormat = "yyyy-MM-dd";
IRestResponse<Person> resp = _client.Get<Person>(req);
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)
@ -63,7 +65,9 @@ namespace TMDbLib.Client
if (endDate != null)
req.AddParameter("endDate", endDate.Value.ToString("yyyy-MM-dd"));
IRestResponse<T> resp = _client.Get<T>(req);
IRestResponse<T> resp = _client.Get<T>(req);
if (resp.ErrorException != null)
throw resp.ErrorException;
return resp.Data;
}

View File

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