From 19f4c50dabd6a4c29749a9c758e7e0da99d9e31f Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 20 Oct 2016 21:19:01 +0200 Subject: rename and move TALER_EXCHANGE_json_get_error_code to TALER_JSON_get_error_code --- src/json/json.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/json/json.c') diff --git a/src/json/json.c b/src/json/json.c index 8f21447ec..74559e6c5 100644 --- a/src/json/json.c +++ b/src/json/json.c @@ -50,4 +50,33 @@ TALER_JSON_hash (const json_t *json, } + +/** + * 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_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; +} + + + /* End of json/json.c */ -- cgit v1.2.3