From 2eb8209386dc20b8f2cadb746a1c36db6453baa6 Mon Sep 17 00:00:00 2001
From: Jason Elie Bou Kheir <5115126+jasonboukheir@users.noreply.github.com>
Date: Sun, 19 Jun 2022 13:58:03 -0700
Subject: [PATCH] feat(api): add `AlgoApiException` that can be thrown from an
`ErrorResponse`
---
.../NodeServices/Networking/ErrorResponse.cs | 26 +++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/Runtime/CareBoo.AlgoSdk/NodeServices/Networking/ErrorResponse.cs b/Runtime/CareBoo.AlgoSdk/NodeServices/Networking/ErrorResponse.cs
index 9af140923..d135c32d7 100644
--- a/Runtime/CareBoo.AlgoSdk/NodeServices/Networking/ErrorResponse.cs
+++ b/Runtime/CareBoo.AlgoSdk/NodeServices/Networking/ErrorResponse.cs
@@ -4,6 +4,24 @@
namespace AlgoSdk
{
+ ///
+ /// An Exception thrown from an .
+ ///
+ public class AlgoApiException : Exception
+ {
+ readonly ErrorResponse error;
+
+ public AlgoApiException(ErrorResponse error) : base(error.Message)
+ {
+ this.error = error;
+ }
+
+ ///
+ /// The that threw this exception.
+ ///
+ public ErrorResponse Error => error;
+ }
+
///
/// An error response from algorand APIs with optional data field.
///
@@ -41,6 +59,14 @@ public override string ToString()
return Message;
}
+ public void ThrowIfError()
+ {
+ if (this)
+ {
+ throw new AlgoApiException(this);
+ }
+ }
+
public bool IsError => Code >= 400 || !string.IsNullOrWhiteSpace(Message);
public static implicit operator bool(ErrorResponse error)