From 7fc752ecaa00aaf7478e8ef5d7391c976c2180c7 Mon Sep 17 00:00:00 2001 From: Neil Boyd Date: Mon, 16 Oct 2017 15:33:28 +0200 Subject: [PATCH 1/2] Add StatusCode and ToString() to BasicApiException --- OpenAPI Client/Exception/BasicApiException.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/OpenAPI Client/Exception/BasicApiException.cs b/OpenAPI Client/Exception/BasicApiException.cs index 4459c70..aa2c9c4 100644 --- a/OpenAPI Client/Exception/BasicApiException.cs +++ b/OpenAPI Client/Exception/BasicApiException.cs @@ -1,15 +1,23 @@ - +using System.Net; + namespace Bol.OpenAPI.Exception { public class BasicApiException : System.ApplicationException { + public HttpStatusCode StatusCode { get; set; } public string Status { get; set; } public BasicApiException() { } - public BasicApiException(string status, string message) : base(message) - { - this.Status = status; - } + public BasicApiException(HttpStatusCode statusCode, string status, string message) : base(message) + { + StatusCode = statusCode; + Status = status; + } + + public override string ToString() + { + return $"[{StatusCode} {Status} {Message}]"; + } } } From c70ae4c4d22e4811fc37dbc0103b13b79f84a82f Mon Sep 17 00:00:00 2001 From: Neil Boyd Date: Fri, 19 Jan 2018 00:05:00 +0100 Subject: [PATCH 2/2] Use the new constructor --- OpenAPI Client/Exception/Handler/ExceptionHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenAPI Client/Exception/Handler/ExceptionHandler.cs b/OpenAPI Client/Exception/Handler/ExceptionHandler.cs index 41463e3..e7be91a 100644 --- a/OpenAPI Client/Exception/Handler/ExceptionHandler.cs +++ b/OpenAPI Client/Exception/Handler/ExceptionHandler.cs @@ -14,7 +14,7 @@ public static BasicApiException HandleBasicApiException(HttpWebResponse response StreamReader reader = new StreamReader(stream, Encoding.UTF8); string responseString = reader.ReadToEnd(); Error error = JsonConvert.DeserializeObject(responseString); - return new BasicApiException(error.Code, error.Message); + return new BasicApiException(response.StatusCode, error.Code, error.Message); } } }