From 9bfeec352b95873bc94b96947a8dd335838f3e8b Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 4 Feb 2020 20:57:11 +0100 Subject: fix #6065 --- src/exchange/taler-exchange-httpd_mhd.c | 9 ++-- src/exchange/taler-exchange-httpd_refresh_melt.c | 2 +- src/exchange/taler-exchange-httpd_refresh_reveal.c | 2 +- src/exchange/taler-exchange-httpd_refund.c | 57 ++++++++-------------- src/exchange/taler-exchange-httpd_reserve_status.c | 2 +- .../taler-exchange-httpd_reserve_withdraw.c | 2 +- src/exchange/taler-exchange-httpd_responses.c | 2 +- src/include/taler_error_codes.h | 5 ++ 8 files changed, 34 insertions(+), 47 deletions(-) diff --git a/src/exchange/taler-exchange-httpd_mhd.c b/src/exchange/taler-exchange-httpd_mhd.c index 53944b6a7..0f2ce033a 100644 --- a/src/exchange/taler-exchange-httpd_mhd.c +++ b/src/exchange/taler-exchange-httpd_mhd.c @@ -128,11 +128,10 @@ TEH_MHD_handler_send_json_pack_error (struct TEH_RequestHandler *rh, (void) connection_cls; (void) upload_data; (void) upload_data_size; - return TALER_MHD_reply_json_pack (connection, - rh->response_code, - "{s:s}", - "error", - rh->data); + return TALER_MHD_reply_with_error (connection, + rh->response_code, + TALER_EC_METHOD_INVALID, + rh->data); } diff --git a/src/exchange/taler-exchange-httpd_refresh_melt.c b/src/exchange/taler-exchange-httpd_refresh_melt.c index 71200037d..c7dc700f7 100644 --- a/src/exchange/taler-exchange-httpd_refresh_melt.c +++ b/src/exchange/taler-exchange-httpd_refresh_melt.c @@ -69,7 +69,7 @@ reply_refresh_melt_insufficient_funds (struct MHD_Connection *connection, return TALER_MHD_reply_json_pack (connection, MHD_HTTP_CONFLICT, "{s:s, s:I, s:o, s:o, s:o, s:o, s:o}", - "error", + "hint", "insufficient funds", "code", (json_int_t) diff --git a/src/exchange/taler-exchange-httpd_refresh_reveal.c b/src/exchange/taler-exchange-httpd_refresh_reveal.c index 3619f9a39..1e03c8e7d 100644 --- a/src/exchange/taler-exchange-httpd_refresh_reveal.c +++ b/src/exchange/taler-exchange-httpd_refresh_reveal.c @@ -108,7 +108,7 @@ reply_refresh_reveal_mismatch (struct MHD_Connection *connection, return TALER_MHD_reply_json_pack (connection, MHD_HTTP_CONFLICT, "{s:s, s:I, s:o}", - "error", "commitment violation", + "hint", "commitment violation", "code", (json_int_t) TALER_EC_REFRESH_REVEAL_COMMITMENT_VIOLATION, diff --git a/src/exchange/taler-exchange-httpd_refund.c b/src/exchange/taler-exchange-httpd_refund.c index 8c6e90302..8e24b9b47 100644 --- a/src/exchange/taler-exchange-httpd_refund.c +++ b/src/exchange/taler-exchange-httpd_refund.c @@ -82,28 +82,6 @@ reply_refund_success (struct MHD_Connection *connection, } -/** - * Generate generic refund failure message. All the details - * are in the @a response_code. The body can be empty. - * - * @param connection connection to the client - * @param response_code response code to generate - * @param ec taler error code to include - * @return MHD result code - */ -static int -reply_refund_failure (struct MHD_Connection *connection, - unsigned int response_code, - enum TALER_ErrorCode ec) -{ - return TALER_MHD_reply_json_pack (connection, - response_code, - "{s:s, s:I}", - "hint", "refund failure", - "code", (json_int_t) ec); -} - - /** * Generate refund conflict failure message. Returns the * transaction list @a tl with the details about the conflict. @@ -194,9 +172,10 @@ refund_transaction (void *cls, if (0 > qs) { if (GNUNET_DB_STATUS_HARD_ERROR == qs) - *mhd_ret = reply_refund_failure (connection, - MHD_HTTP_NOT_FOUND, - TALER_EC_REFUND_COIN_NOT_FOUND); + *mhd_ret = TALER_MHD_reply_with_error (connection, + MHD_HTTP_NOT_FOUND, + TALER_EC_REFUND_COIN_NOT_FOUND, + "database transaction failure"); return qs; } deposit_found = GNUNET_NO; @@ -319,9 +298,10 @@ refund_transaction (void *cls, GNUNET_break_op (0); /* currency mismatch */ TEH_plugin->free_coin_transaction_list (TEH_plugin->cls, tl); - *mhd_ret = reply_refund_failure (connection, - MHD_HTTP_PRECONDITION_FAILED, - TALER_EC_REFUND_CURRENCY_MISSMATCH); + *mhd_ret = TALER_MHD_reply_with_error (connection, + MHD_HTTP_PRECONDITION_FAILED, + TALER_EC_REFUND_CURRENCY_MISSMATCH, + "currencies involved do not match"); return GNUNET_DB_STATUS_HARD_ERROR; } @@ -353,9 +333,10 @@ refund_transaction (void *cls, /* money was already transferred to merchant, can no longer refund */ TEH_plugin->free_coin_transaction_list (TEH_plugin->cls, tl); - *mhd_ret = reply_refund_failure (connection, - MHD_HTTP_GONE, - TALER_EC_REFUND_MERCHANT_ALREADY_PAID); + *mhd_ret = TALER_MHD_reply_with_error (connection, + MHD_HTTP_GONE, + TALER_EC_REFUND_MERCHANT_ALREADY_PAID, + "money already sent to merchant"); return GNUNET_DB_STATUS_HARD_ERROR; } @@ -366,9 +347,10 @@ refund_transaction (void *cls, GNUNET_break_op (0); /* cannot refund more than original value */ TEH_plugin->free_coin_transaction_list (TEH_plugin->cls, tl); - *mhd_ret = reply_refund_failure (connection, - MHD_HTTP_PRECONDITION_FAILED, - TALER_EC_REFUND_INSUFFICIENT_FUNDS); + *mhd_ret = TALER_MHD_reply_with_error (connection, + MHD_HTTP_PRECONDITION_FAILED, + TALER_EC_REFUND_INSUFFICIENT_FUNDS, + "refund requested exceeds original value"); return GNUNET_DB_STATUS_HARD_ERROR; } /* Check refund fee matches fee of denomination key! */ @@ -481,9 +463,10 @@ verify_and_execute_refund (struct MHD_Connection *connection, if (0 > qs) { GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); - return reply_refund_failure (connection, - MHD_HTTP_NOT_FOUND, - TALER_EC_REFUND_COIN_NOT_FOUND); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_NOT_FOUND, + TALER_EC_REFUND_COIN_NOT_FOUND, + "denomination of coin to be refunded not found in DB"); } } diff --git a/src/exchange/taler-exchange-httpd_reserve_status.c b/src/exchange/taler-exchange-httpd_reserve_status.c index 89bf8b38a..e2d35aaec 100644 --- a/src/exchange/taler-exchange-httpd_reserve_status.c +++ b/src/exchange/taler-exchange-httpd_reserve_status.c @@ -164,7 +164,7 @@ TEH_RESERVE_handler_reserve_status (struct TEH_RequestHandler *rh, return TALER_MHD_reply_json_pack (connection, MHD_HTTP_NOT_FOUND, "{s:s, s:s, s:I}", - "error", "Reserve not found", + "hint", "Reserve not found", "parameter", "reserve_pub", "code", (json_int_t) diff --git a/src/exchange/taler-exchange-httpd_reserve_withdraw.c b/src/exchange/taler-exchange-httpd_reserve_withdraw.c index 86633cd98..9daad0a02 100644 --- a/src/exchange/taler-exchange-httpd_reserve_withdraw.c +++ b/src/exchange/taler-exchange-httpd_reserve_withdraw.c @@ -74,7 +74,7 @@ reply_reserve_withdraw_insufficient_funds (struct MHD_Connection *connection, return TALER_MHD_reply_json_pack (connection, MHD_HTTP_CONFLICT, "{s:s, s:I, s:o, s:o}", - "error", "Insufficient funds", + "hint", "insufficient funds", "code", (json_int_t) TALER_EC_WITHDRAW_INSUFFICIENT_FUNDS, diff --git a/src/exchange/taler-exchange-httpd_responses.c b/src/exchange/taler-exchange-httpd_responses.c index c88a8a254..90ca14c88 100644 --- a/src/exchange/taler-exchange-httpd_responses.c +++ b/src/exchange/taler-exchange-httpd_responses.c @@ -446,7 +446,7 @@ TEH_RESPONSE_reply_coin_insufficient_funds (struct MHD_Connection *connection, return TALER_MHD_reply_json_pack (connection, MHD_HTTP_CONFLICT, "{s:s, s:I, s:o}", - "error", "insufficient funds", + "hint", "insufficient funds", "code", (json_int_t) ec, "history", history); } diff --git a/src/include/taler_error_codes.h b/src/include/taler_error_codes.h index ac7f92888..917ac36db 100644 --- a/src/include/taler_error_codes.h +++ b/src/include/taler_error_codes.h @@ -80,6 +80,11 @@ enum TALER_ErrorCode */ TALER_EC_JSON_ALLOCATION_FAILURE = 7, + /** + * HTTP method invalid for this URL. + */ + TALER_EC_METHOD_INVALID = 8, + /** * The exchange failed to even just initialize its connection to the * database. This response is provided with HTTP status code -- cgit v1.2.3