minimal improvements for ApiResponse
This commit is contained in:
16
Pilz.Net/Api/ApiException.cs
Normal file
16
Pilz.Net/Api/ApiException.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace Pilz.Net.Api;
|
||||
|
||||
public class ApiException : Exception
|
||||
{
|
||||
public ApiException()
|
||||
{
|
||||
}
|
||||
|
||||
public ApiException(string? message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public ApiException(string? message, Exception? innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,6 @@ public record class ApiResponse(
|
||||
public void EnsureOk()
|
||||
{
|
||||
if (!IsOk)
|
||||
throw new Exception("Api return is not ok!");
|
||||
throw new ApiException("Api return is not ok: " + StatusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,10 @@ public record class ApiResponse<T>(
|
||||
public bool IsOk => StatusCode == HttpStatusCode.OK && Message is not null;
|
||||
|
||||
[MemberNotNull(nameof(Message))]
|
||||
public void EnsureOk()
|
||||
public T EnsureOk()
|
||||
{
|
||||
if (!IsOk)
|
||||
throw new Exception("Api return is not ok!");
|
||||
throw new ApiException("Api return is not ok: " + StatusCode);
|
||||
return Message;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user