minimal improvements for ApiResponse

This commit is contained in:
Pascal Schedel
2024-10-23 12:51:36 +02:00
parent 3cec6983b8
commit 59e9499d92
3 changed files with 20 additions and 3 deletions

View File

@@ -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;
}
}