diff --git a/Pilz.Net/Api/ApiException.cs b/Pilz.Net/Api/ApiException.cs index 3e07263..051bce1 100644 --- a/Pilz.Net/Api/ApiException.cs +++ b/Pilz.Net/Api/ApiException.cs @@ -1,11 +1,20 @@ -namespace Pilz.Net.Api; +using System.Net; + +namespace Pilz.Net.Api; public class ApiException : Exception { + public HttpStatusCode StatusCode { get; } + public ApiException() { } + public ApiException(string? message, HttpStatusCode statusCode) : base(message) + { + StatusCode = statusCode; + } + public ApiException(string? message) : base(message) { } diff --git a/Pilz.Net/Api/ApiResponse.cs b/Pilz.Net/Api/ApiResponse.cs index 020c64f..95d076d 100644 --- a/Pilz.Net/Api/ApiResponse.cs +++ b/Pilz.Net/Api/ApiResponse.cs @@ -10,6 +10,6 @@ public record class ApiResponse( public void EnsureOk() { if (!IsOk) - throw new ApiException("Api return is not ok: " + StatusCode); + throw new ApiException("Api return is not ok: " + StatusCode, StatusCode); } } diff --git a/Pilz.Net/Api/ApiResponse{T}.cs b/Pilz.Net/Api/ApiResponse{T}.cs index f3228c3..1375644 100644 --- a/Pilz.Net/Api/ApiResponse{T}.cs +++ b/Pilz.Net/Api/ApiResponse{T}.cs @@ -15,7 +15,7 @@ public record class ApiResponse( public T EnsureOk() { if (!IsOk) - throw new ApiException("Api return is not ok: " + StatusCode); + throw new ApiException("Api return is not ok or message invalid: " + StatusCode, StatusCode); return Message; } }