summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/exchange/taler-exchange-httpd_melt.c6
-rw-r--r--src/exchange/taler-exchange-httpd_refreshes_reveal.c7
-rw-r--r--src/exchange/taler-exchange-httpd_refund.c13
-rw-r--r--src/exchange/taler-exchange-httpd_responses.c11
-rw-r--r--src/exchange/taler-exchange-httpd_withdraw.c6
-rw-r--r--src/include/taler_json_lib.h10
6 files changed, 20 insertions, 33 deletions
diff --git a/src/exchange/taler-exchange-httpd_melt.c b/src/exchange/taler-exchange-httpd_melt.c
index 42780826..071a9c38 100644
--- a/src/exchange/taler-exchange-httpd_melt.c
+++ b/src/exchange/taler-exchange-httpd_melt.c
@@ -69,11 +69,7 @@ reply_melt_insufficient_funds (
return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_CONFLICT,
- GNUNET_JSON_pack_string ("hint",
- TALER_ErrorCode_get_hint (
- TALER_EC_EXCHANGE_MELT_INSUFFICIENT_FUNDS)),
- GNUNET_JSON_pack_uint64 ("code",
- TALER_EC_EXCHANGE_MELT_INSUFFICIENT_FUNDS),
+ TALER_JSON_pack_ec (TALER_EC_EXCHANGE_MELT_INSUFFICIENT_FUNDS),
GNUNET_JSON_pack_data_auto ("coin_pub",
coin_pub),
TALER_JSON_pack_amount ("original_value",
diff --git a/src/exchange/taler-exchange-httpd_refreshes_reveal.c b/src/exchange/taler-exchange-httpd_refreshes_reveal.c
index 5cbb6e6c..2a5c3aca 100644
--- a/src/exchange/taler-exchange-httpd_refreshes_reveal.c
+++ b/src/exchange/taler-exchange-httpd_refreshes_reveal.c
@@ -387,11 +387,8 @@ refreshes_reveal_transaction (void *cls,
*mhd_ret = TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_CONFLICT,
- GNUNET_JSON_pack_string ("hint",
- TALER_ErrorCode_get_hint (
- TALER_EC_EXCHANGE_REFRESHES_REVEAL_COMMITMENT_VIOLATION)),
- GNUNET_JSON_pack_uint64 ("code",
- TALER_EC_EXCHANGE_REFRESHES_REVEAL_COMMITMENT_VIOLATION),
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_REFRESHES_REVEAL_COMMITMENT_VIOLATION),
GNUNET_JSON_pack_data_auto ("rc_expected",
&rc_expected));
return GNUNET_DB_STATUS_HARD_ERROR;
diff --git a/src/exchange/taler-exchange-httpd_refund.c b/src/exchange/taler-exchange-httpd_refund.c
index c2b2d800..2ea19b7e 100644
--- a/src/exchange/taler-exchange-httpd_refund.c
+++ b/src/exchange/taler-exchange-httpd_refund.c
@@ -233,11 +233,7 @@ refund_transaction (void *cls,
MHD_HTTP_PRECONDITION_FAILED,
TALER_JSON_pack_amount ("detail",
&ref->refund_amount),
- GNUNET_JSON_pack_string ("hint",
- TALER_ErrorCode_get_hint (
- TALER_EC_EXCHANGE_REFUND_INCONSISTENT_AMOUNT)),
- GNUNET_JSON_pack_uint64 ("code",
- TALER_EC_EXCHANGE_REFUND_INCONSISTENT_AMOUNT),
+ TALER_JSON_pack_ec (TALER_EC_EXCHANGE_REFUND_INCONSISTENT_AMOUNT),
GNUNET_JSON_pack_array_steal ("history",
TEH_RESPONSE_compile_transaction_history (
&refund->coin.coin_pub,
@@ -332,11 +328,8 @@ refund_transaction (void *cls,
MHD_HTTP_CONFLICT,
GNUNET_JSON_pack_string ("detail",
"total amount refunded exceeds total amount deposited for this coin"),
- GNUNET_JSON_pack_string ("hint",
- TALER_ErrorCode_get_hint (
- TALER_EC_EXCHANGE_REFUND_CONFLICT_DEPOSIT_INSUFFICIENT)),
- GNUNET_JSON_pack_uint64 ("code",
- TALER_EC_EXCHANGE_REFUND_CONFLICT_DEPOSIT_INSUFFICIENT),
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_REFUND_CONFLICT_DEPOSIT_INSUFFICIENT),
GNUNET_JSON_pack_array_steal ("history",
TEH_RESPONSE_compile_transaction_history (
&refund->coin.coin_pub,
diff --git a/src/exchange/taler-exchange-httpd_responses.c b/src/exchange/taler-exchange-httpd_responses.c
index e05b537e..72d1ddb7 100644
--- a/src/exchange/taler-exchange-httpd_responses.c
+++ b/src/exchange/taler-exchange-httpd_responses.c
@@ -450,8 +450,7 @@ TEH_RESPONSE_reply_unknown_denom_pub_hash (
return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_NOT_FOUND,
- GNUNET_JSON_pack_uint64 ("code",
- TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN),
+ TALER_JSON_pack_ec (TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN),
GNUNET_JSON_pack_time_abs ("timestamp",
now),
GNUNET_JSON_pack_data_auto ("exchange_pub",
@@ -501,8 +500,7 @@ TEH_RESPONSE_reply_expired_denom_pub_hash (
return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_GONE,
- GNUNET_JSON_pack_uint64 ("code",
- ec),
+ TALER_JSON_pack_ec (ec),
GNUNET_JSON_pack_string ("oper",
oper),
GNUNET_JSON_pack_time_abs ("timestamp",
@@ -550,10 +548,7 @@ TEH_RESPONSE_reply_coin_insufficient_funds (
return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_CONFLICT,
- GNUNET_JSON_pack_string ("hint",
- TALER_ErrorCode_get_hint (ec)),
- GNUNET_JSON_pack_uint64 ("code",
- ec),
+ TALER_JSON_pack_ec (ec),
GNUNET_JSON_pack_array_steal ("history",
history));
}
diff --git a/src/exchange/taler-exchange-httpd_withdraw.c b/src/exchange/taler-exchange-httpd_withdraw.c
index a5e6db0a..7be56084 100644
--- a/src/exchange/taler-exchange-httpd_withdraw.c
+++ b/src/exchange/taler-exchange-httpd_withdraw.c
@@ -81,11 +81,7 @@ reply_withdraw_insufficient_funds (
return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_CONFLICT,
- GNUNET_JSON_pack_string ("hint",
- TALER_ErrorCode_get_hint (
- TALER_EC_EXCHANGE_WITHDRAW_INSUFFICIENT_FUNDS)),
- GNUNET_JSON_pack_uint64 ("code",
- TALER_EC_EXCHANGE_WITHDRAW_INSUFFICIENT_FUNDS),
+ TALER_JSON_pack_ec (TALER_EC_EXCHANGE_WITHDRAW_INSUFFICIENT_FUNDS),
TALER_JSON_pack_amount ("balance",
&balance),
GNUNET_JSON_pack_array_steal ("history",
diff --git a/src/include/taler_json_lib.h b/src/include/taler_json_lib.h
index f338d44a..ea621cea 100644
--- a/src/include/taler_json_lib.h
+++ b/src/include/taler_json_lib.h
@@ -80,6 +80,16 @@ TALER_JSON_pack_time_abs_nbo (const char *name,
/**
+ * Put an error code into a JSON reply, including
+ * both the numeric value and the hint.
+ *
+ * @param ec error code to encode using canonical field names
+ */
+#define TALER_JSON_pack_ec(ec) \
+ GNUNET_JSON_pack_string ("hint", TALER_ErrorCode_get_hint (ec)), \
+ GNUNET_JSON_pack_uint64 ("code", ec)
+
+/**
* Generate packer instruction for a JSON field of type
* absolute time creating a human-readable timestamp.
*