add statuscode to apiexception
This commit is contained in:
@@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public record class ApiResponse<T>(
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user