diff --git a/src/CommonLibrariesForNET/AuthenticationClient.cs b/src/CommonLibrariesForNET/AuthenticationClient.cs index 02df6e80..d777dee0 100644 --- a/src/CommonLibrariesForNET/AuthenticationClient.cs +++ b/src/CommonLibrariesForNET/AuthenticationClient.cs @@ -182,7 +182,7 @@ public async Task TokenRefreshAsync(string clientId, string refreshToken, string else { var errorResponse = JsonConvert.DeserializeObject(response); - throw new ForceException(errorResponse.Error, errorResponse.ErrorDescription); + throw new ForceException(errorResponse.Error, errorResponse.ErrorDescription, responseMessage.StatusCode); } } @@ -220,7 +220,7 @@ public async Task GetLatestVersionAsync() else { var errorResponse = JsonConvert.DeserializeObject(response); - throw new ForceException(errorResponse.Error, errorResponse.ErrorDescription); + throw new ForceException(errorResponse.Error, errorResponse.ErrorDescription, responseMessage.StatusCode); } } catch (Exception ex) diff --git a/src/CommonLibrariesForNET/JsonHttpClient.cs b/src/CommonLibrariesForNET/JsonHttpClient.cs index 26d67132..620c6d78 100644 --- a/src/CommonLibrariesForNET/JsonHttpClient.cs +++ b/src/CommonLibrariesForNET/JsonHttpClient.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Text; @@ -23,10 +24,10 @@ public JsonHttpClient(string instanceUrl, string apiVersion, string accessToken, HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); } - private static ForceException ParseForceException(string responseMessage) + private static ForceException ParseForceException(string responseMessage, HttpStatusCode statusCode) { var errorResponse = JsonConvert.DeserializeObject(responseMessage); - return new ForceException(errorResponse[0].ErrorCode, errorResponse[0].Message); + return new ForceException(errorResponse[0].ErrorCode, errorResponse[0].Message, statusCode); } // GET @@ -61,7 +62,7 @@ public async Task HttpGetAsync(Uri uri) } catch (BaseHttpClientException e) { - throw ParseForceException(e.Message); + throw ParseForceException(e.Message, e.GetStatus()); } } @@ -87,7 +88,7 @@ public async Task> HttpGetAsync(string urlSuffix, string nodeName) } catch (BaseHttpClientException e) { - throw ParseForceException(e.Message); + throw ParseForceException(e.Message, e.GetStatus()); } } while (!string.IsNullOrEmpty(next)); @@ -150,7 +151,7 @@ public async Task HttpPostAsync(object inputObject, Uri uri) } catch (BaseHttpClientException e) { - throw ParseForceException(e.Message); + throw ParseForceException(e.Message, e.GetStatus()); } } @@ -193,7 +194,7 @@ public async Task HttpBinaryDataPostAsync(string urlSuffix, object inputOb return JsonConvert.DeserializeObject(response); } - throw ParseForceException(response); + throw ParseForceException(response, responseMessage.StatusCode); } // PATCH @@ -238,7 +239,7 @@ public async Task HttpPatchAsync(object inputObject, Uri uri) } catch (BaseHttpClientException e) { - throw ParseForceException(e.Message); + throw ParseForceException(e.Message, e.GetStatus()); } } @@ -264,7 +265,7 @@ public async Task HttpPatchAsync(object inputObject, Uri uri, N } catch (BaseHttpClientException e) { - throw ParseForceException(e.Message); + throw ParseForceException(e.Message, e.GetStatus()); } } @@ -285,7 +286,7 @@ public async Task HttpDeleteAsync(string urlSuffix) } catch (BaseHttpClientException e) { - throw ParseForceException(e.Message); + throw ParseForceException(e.Message, e.GetStatus()); } } } diff --git a/src/CommonLibrariesForNET/XmlHttpClient.cs b/src/CommonLibrariesForNET/XmlHttpClient.cs index d9ee5713..63860380 100644 --- a/src/CommonLibrariesForNET/XmlHttpClient.cs +++ b/src/CommonLibrariesForNET/XmlHttpClient.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Net; using System.Net.Http; using System.Threading.Tasks; using System.Xml; @@ -38,7 +39,7 @@ public async Task HttpGetAsync(Uri uri) } catch (BaseHttpClientException e) { - throw ParseForceException(e.Message); + throw ParseForceException(e.Message, e.GetStatus()); } } @@ -60,16 +61,16 @@ public async Task HttpPostAsync(object inputObject, Uri uri) } catch (BaseHttpClientException e) { - throw ParseForceException(e.Message); + throw ParseForceException(e.Message, e.GetStatus()); } } // HELPER METHODS - private static ForceException ParseForceException(string responseMessage) + private static ForceException ParseForceException(string responseMessage, HttpStatusCode statusCode) { var errorResponse = DeserializeXmlString(responseMessage); - return new ForceException(errorResponse.ErrorCode, errorResponse.Message); + return new ForceException(errorResponse.ErrorCode, errorResponse.Message, statusCode); } private static string SerializeXmlObject(object inputObject)