diff --git a/IotaCSharpApi/Api/Exception/IotaApiException.cs b/IotaCSharpApi/Api/Exception/IotaApiException.cs
index 1d52a4b..abdced5 100644
--- a/IotaCSharpApi/Api/Exception/IotaApiException.cs
+++ b/IotaCSharpApi/Api/Exception/IotaApiException.cs
@@ -13,5 +13,15 @@ public class IotaApiException : System.Exception
public IotaApiException(string error) : base(error)
{
}
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The exception message.
+ /// The inner exception.
+ public IotaApiException(string message, System.Exception innerException)
+ : base(message, innerException)
+ {
+ }
}
}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Utils/Rest/JsonWebClient.cs b/IotaCSharpApi/Api/Utils/Rest/JsonWebClient.cs
index 800b281..0ebcd8a 100644
--- a/IotaCSharpApi/Api/Utils/Rest/JsonWebClient.cs
+++ b/IotaCSharpApi/Api/Utils/Rest/JsonWebClient.cs
@@ -60,13 +60,20 @@ public TResponse GetPOSTResponseSync(Uri uri, string data)
}
catch (WebException ex)
{
- Console.WriteLine("catched: " + ex.ToString() + ex.Message);
-
using (var stream = ex.Response.GetResponseStream())
using (var reader = new StreamReader(stream))
{
- String errorResponse = reader.ReadToEnd();
- throw new IotaApiException(JsonConvert.DeserializeObject(errorResponse).Error);
+ var errorResponse = reader.ReadToEnd();
+ string deserialized;
+ try
+ {
+ deserialized = JsonConvert.DeserializeObject(errorResponse).Error;
+ }
+ catch (System.Exception)
+ {
+ deserialized = "Caught WebException but was unable to deserialize content (no JSON).";
+ }
+ throw new IotaApiException(deserialized, ex);
}
}
}