From fc5e4039b2e6a9209098906a16ca098cd9105c09 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Thu, 29 Nov 2018 14:59:43 -0500 Subject: [PATCH] SPARK-1907 .value() on failed result should be null instead of an exception that nobody will remember to catch --- src/client/spark_api/api/Result.cs | 7 ++++++- src/lib/api/public/Result.h | 7 +------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/client/spark_api/api/Result.cs b/src/client/spark_api/api/Result.cs index 5a473c0e0..52084ac4c 100644 --- a/src/client/spark_api/api/Result.cs +++ b/src/client/spark_api/api/Result.cs @@ -37,7 +37,12 @@ namespace bts.api.core public T value { get { if (success) return _result; - else throw new ApiException(error_message); + else { + if (typeof(T).IsValueType) { throw new ApiException(error_message); } + else { + return default(T);// always null + } + } } } public bool success { get { return _code == ApiError.Success; } } diff --git a/src/lib/api/public/Result.h b/src/lib/api/public/Result.h index de3625775..c63401f89 100644 --- a/src/lib/api/public/Result.h +++ b/src/lib/api/public/Result.h @@ -57,7 +57,7 @@ public: std::shared_ptr result() const { if (success()) return _t; - else throw ApiException(std::string(error_message())); + else return nullptr; } bool success() const { return _code == ApiError::SUCCESS; } @@ -66,13 +66,8 @@ public: const char* error_message() const { return error_string(_code); } ~Result() {} - - // Is not a type?? - // typedef std::function)> OnResponse; }; -//template -//using OnResponse = std::function)>; }}//namespace