diff --git a/TMDbLib/Client/TMDbClient.cs b/TMDbLib/Client/TMDbClient.cs index 8440085..29301e1 100644 --- a/TMDbLib/Client/TMDbClient.cs +++ b/TMDbLib/Client/TMDbClient.cs @@ -60,10 +60,14 @@ namespace TMDbLib.Client public void GetConfig() { RestRequest req = new RestRequest("configuration"); - IRestResponse resp = _client.Get(req); + IRestResponse resp = _client.Get(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; diff --git a/TMDbLib/Client/TMDbClientCollections.cs b/TMDbLib/Client/TMDbClientCollections.cs index 43cda71..e287309 100644 --- a/TMDbLib/Client/TMDbClientCollections.cs +++ b/TMDbLib/Client/TMDbClientCollections.cs @@ -33,7 +33,9 @@ namespace TMDbLib.Client req.DateFormat = "yyyy-MM-dd"; - IRestResponse resp = _client.Get(req); + IRestResponse resp = _client.Get(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 resp = _client.Get(req); + IRestResponse resp = _client.Get(req); + if (resp.ErrorException != null) + throw resp.ErrorException; return resp.Data; } diff --git a/TMDbLib/Client/TMDbClientCompanies.cs b/TMDbLib/Client/TMDbClientCompanies.cs index 8e72149..148e7c1 100644 --- a/TMDbLib/Client/TMDbClientCompanies.cs +++ b/TMDbLib/Client/TMDbClientCompanies.cs @@ -25,7 +25,9 @@ namespace TMDbLib.Client req.DateFormat = "yyyy-MM-dd"; - IRestResponse resp = _client.Get(req); + IRestResponse resp = _client.Get(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 resp = _client.Get(req); + IRestResponse resp = _client.Get(req); + if (resp.ErrorException != null) + throw resp.ErrorException; return resp.Data; } diff --git a/TMDbLib/Client/TMDbClientGenres.cs b/TMDbLib/Client/TMDbClientGenres.cs index ed23e05..16b144f 100644 --- a/TMDbLib/Client/TMDbClientGenres.cs +++ b/TMDbLib/Client/TMDbClientGenres.cs @@ -19,7 +19,9 @@ namespace TMDbLib.Client if (language != null) req.AddParameter("language", language); - IRestResponse resp = _client.Get(req); + IRestResponse resp = _client.Get(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> resp = _client.Get>(req); + IRestResponse> resp = _client.Get>(req); + if (resp.ErrorException != null) + throw resp.ErrorException; return resp.Data; } diff --git a/TMDbLib/Client/TMDbClientKeywords.cs b/TMDbLib/Client/TMDbClientKeywords.cs index da32346..05110e0 100644 --- a/TMDbLib/Client/TMDbClientKeywords.cs +++ b/TMDbLib/Client/TMDbClientKeywords.cs @@ -11,7 +11,9 @@ namespace TMDbLib.Client RestRequest req = new RestRequest("keyword/{id}"); req.AddUrlSegment("id", id.ToString()); - IRestResponse resp = _client.Get(req); + IRestResponse resp = _client.Get(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> resp = _client.Get>(req); + IRestResponse> resp = _client.Get>(req); + if (resp.ErrorException != null) + throw resp.ErrorException; return resp.Data; } diff --git a/TMDbLib/Client/TMDbClientLists.cs b/TMDbLib/Client/TMDbClientLists.cs index 7efd087..e5f23a3 100644 --- a/TMDbLib/Client/TMDbClientLists.cs +++ b/TMDbLib/Client/TMDbClientLists.cs @@ -12,7 +12,9 @@ namespace TMDbLib.Client req.DateFormat = "yyyy-MM-dd"; - IRestResponse resp = _client.Get(req); + IRestResponse resp = _client.Get(req); + if (resp.ErrorException != null) + throw resp.ErrorException; return resp.Data; } diff --git a/TMDbLib/Client/TMDbClientMovies.cs b/TMDbLib/Client/TMDbClientMovies.cs index 506148f..6591cf6 100644 --- a/TMDbLib/Client/TMDbClientMovies.cs +++ b/TMDbLib/Client/TMDbClientMovies.cs @@ -43,6 +43,8 @@ namespace TMDbLib.Client req.AddParameter("append_to_response", appends); IRestResponse resp = _client.Get(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 resp = _client.Get(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 resp = _client.Get(req); + if (resp.ErrorException != null) + throw resp.ErrorException; return resp.Data; } @@ -207,6 +213,8 @@ namespace TMDbLib.Client req.DateFormat = "yyyy-MM-dd"; IRestResponse> resp = _client.Get>(req); + if (resp.ErrorException != null) + throw resp.ErrorException; return resp.Data; } diff --git a/TMDbLib/Client/TMDbClientPeople.cs b/TMDbLib/Client/TMDbClientPeople.cs index f4bd714..88797ca 100644 --- a/TMDbLib/Client/TMDbClientPeople.cs +++ b/TMDbLib/Client/TMDbClientPeople.cs @@ -26,7 +26,9 @@ namespace TMDbLib.Client req.DateFormat = "yyyy-MM-dd"; - IRestResponse resp = _client.Get(req); + IRestResponse resp = _client.Get(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 resp = _client.Get(req); + IRestResponse resp = _client.Get(req); + if (resp.ErrorException != null) + throw resp.ErrorException; return resp.Data; } diff --git a/TMDbLib/Client/TMDbClientSearch.cs b/TMDbLib/Client/TMDbClientSearch.cs index 8933bc8..607dcb0 100644 --- a/TMDbLib/Client/TMDbClientSearch.cs +++ b/TMDbLib/Client/TMDbClientSearch.cs @@ -25,7 +25,9 @@ namespace TMDbLib.Client if (dateFormat != null) req.DateFormat = dateFormat; - IRestResponse resp = _client.Get(req); + IRestResponse resp = _client.Get(req); + if (resp.ErrorException != null) + throw resp.ErrorException; return resp.Data; }