Skip to content

Add StatusCode and ToString() to BasicApiException #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions OpenAPI Client/Exception/BasicApiException.cs
Original file line number Diff line number Diff line change
@@ -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}]";
}
}
}
2 changes: 1 addition & 1 deletion OpenAPI Client/Exception/Handler/ExceptionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Error>(responseString);
return new BasicApiException(error.Code, error.Message);
return new BasicApiException(response.StatusCode, error.Code, error.Message);
}
}
}
Expand Down