aboutsummaryrefslogtreecommitdiff
path: root/src/exchange-lib/exchange_api_common.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-10-20 21:00:40 +0200
committerChristian Grothoff <christian@grothoff.org>2016-10-20 21:00:40 +0200
commit7341b21fa3d6328f2c85747824899be54668e891 (patch)
treeec9617287fe3514c377dbe06437cd33da6ba1c22 /src/exchange-lib/exchange_api_common.c
parente7875fb26145fcf90aaec4aa8bcb75ace0b40779 (diff)
return taler-specific error codes from C API as well
(#4497/4705)
Diffstat (limited to 'src/exchange-lib/exchange_api_common.c')
-rw-r--r--src/exchange-lib/exchange_api_common.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/exchange-lib/exchange_api_common.c b/src/exchange-lib/exchange_api_common.c
index e6ab2cbc2..445e2f131 100644
--- a/src/exchange-lib/exchange_api_common.c
+++ b/src/exchange-lib/exchange_api_common.c
@@ -28,6 +28,33 @@
/**
+ * Extract the Taler error code from the given @a json object.
+ * Note that #TALER_EC_NONE is returned if no "code" is present.
+ *
+ * @param json response to extract the error code from
+ * @return the "code" value from @a json
+ */
+enum TALER_ErrorCode
+TALER_EXCHANGE_json_get_error_code (const json_t *json)
+{
+ const json_t *jc;
+
+ if (NULL == json)
+ {
+ GNUNET_break_op (0);
+ return TALER_EC_INVALID_RESPONSE;
+ }
+ jc = json_object_get (json, "code");
+ if (NULL == jc)
+ return TALER_EC_NONE;
+ if (json_is_integer (jc))
+ return (enum TALER_ErrorCode) json_integer_value (jc);
+ GNUNET_break_op (0);
+ return TALER_EC_INVALID;
+}
+
+
+/**
* Verify a coins transaction history as returned by the exchange.
*
* @param currency expected currency for the coin