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}]"; + } } } 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); } } }