summaryrefslogtreecommitdiff
path: root/src/json
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-11-25 01:42:55 +0100
committerChristian Grothoff <christian@grothoff.org>2019-11-25 01:42:55 +0100
commit70a210ac4db07a28867e23db13c68aecc117810a (patch)
tree0b93d0f5188fc5b4ff0d9f3e559516912861b42b /src/json
parentb7a5af7fd4ea302df013ad492d8a420efca5864c (diff)
downloadexchange-70a210ac4db07a28867e23db13c68aecc117810a.tar.gz
exchange-70a210ac4db07a28867e23db13c68aecc117810a.tar.bz2
exchange-70a210ac4db07a28867e23db13c68aecc117810a.zip
add another helper
Diffstat (limited to 'src/json')
-rw-r--r--src/json/json.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/json/json.c b/src/json/json.c
index 90fe3dd4f..8d4089795 100644
--- a/src/json/json.c
+++ b/src/json/json.c
@@ -80,4 +80,33 @@ TALER_JSON_get_error_code (const json_t *json)
}
+/**
+ * Extract the Taler error code from the given @a data object, which is expected to be in JSON.
+ * Note that #TALER_EC_INVALID is returned if no "code" is present or if @a data is not in JSON.
+ *
+ * @param data response to extract the error code from
+ * @param data_size number of bytes in @a data
+ * @return the "code" value from @a json
+ */
+enum TALER_ErrorCode
+TALER_JSON_get_error_code2 (const void *data,
+ size_t data_size)
+{
+ json_t *json;
+ enum TALER_ErrorCode ec;
+ json_error_t err;
+
+ json = json_loads (data,
+ data_size,
+ &err);
+ if (NULL == json)
+ return TALER_EC_INVALID;
+ ec = TALER_JSON_get_error_code (json);
+ json_decref (json);
+ if (ec == TALER_EC_NONE)
+ return TALER_EC_INVALID;
+ return ec;
+}
+
+
/* End of json/json.c */