diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-01-18 11:58:00 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-01-18 11:58:00 +0100 |
commit | cd47c8e0afb66f2d9053082940f208347551b3a8 (patch) | |
tree | 1e50b6a5448cbab3c7422baabc8f6f67e77890ac | |
parent | d99be82b37fc00dec9b16822e815216c979d70cd (diff) |
only log things as ERROR that are actually ERRORs; return 502 instead of 500 on abort failure due to malformed exchange reply
-rw-r--r-- | src/backend/taler-merchant-httpd_post-orders-ID-abort.c | 16 | ||||
-rw-r--r-- | src/lib/merchant_api_delete_reserve.c | 4 | ||||
-rw-r--r-- | src/lib/merchant_api_tip_pickup2.c | 13 | ||||
-rw-r--r-- | src/testing/test_merchant_api_twisted.c | 2 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_abort_order.c | 5 |
5 files changed, 30 insertions, 10 deletions
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-abort.c b/src/backend/taler-merchant-httpd_post-orders-ID-abort.c index 4f6b8667..a7dadb69 100644 --- a/src/backend/taler-merchant-httpd_post-orders-ID-abort.c +++ b/src/backend/taler-merchant-httpd_post-orders-ID-abort.c @@ -343,6 +343,7 @@ static void generate_success_response (struct AbortContext *ac) { json_t *refunds; + unsigned int hc = MHD_HTTP_OK; refunds = json_array (); if (NULL == refunds) @@ -359,15 +360,22 @@ generate_success_response (struct AbortContext *ac) struct RefundDetails *rdi = &ac->rd[i]; json_t *detail; + if ( (MHD_HTTP_BAD_REQUEST <= rdi->http_status) || + (0 == rdi->http_status) || + (NULL == rdi->exchange_reply) ) + hc = MHD_HTTP_BAD_GATEWAY; detail = (MHD_HTTP_OK != rdi->http_status) - ? json_pack ("{s:s, s:I, s:I, s:O}", + ? json_pack ("{s:s, s:I, s:I, s:O?}", "type", "failure", "exchange_status", (json_int_t) rdi->http_status, "exchange_code", - (json_int_t) TALER_JSON_get_error_code ( - rdi->exchange_reply), + (json_int_t) + (NULL != rdi->exchange_reply) + ? TALER_JSON_get_error_code ( + rdi->exchange_reply) + : TALER_EC_GENERIC_INVALID_RESPONSE, "exchange_reply", rdi->exchange_reply) : json_pack ("{s:s, s:I, s:o, s:o}", @@ -395,7 +403,7 @@ generate_success_response (struct AbortContext *ac) /* Resume and send back the response. */ resume_abort_with_response (ac, - MHD_HTTP_OK, + hc, TALER_MHD_make_json_pack ("{s:o}", "refunds", refunds)); diff --git a/src/lib/merchant_api_delete_reserve.c b/src/lib/merchant_api_delete_reserve.c index 64360a87..9a8d3991 100644 --- a/src/lib/merchant_api_delete_reserve.c +++ b/src/lib/merchant_api_delete_reserve.c @@ -92,6 +92,10 @@ handle_delete_reserve_finished (void *cls, { case MHD_HTTP_NO_CONTENT: break; + case MHD_HTTP_NOT_FOUND: + hr.ec = TALER_JSON_get_error_code (json); + hr.hint = TALER_JSON_get_error_hint (json); + break; default: /* unexpected response code */ hr.ec = TALER_JSON_get_error_code (json); diff --git a/src/lib/merchant_api_tip_pickup2.c b/src/lib/merchant_api_tip_pickup2.c index 946d961e..af57a584 100644 --- a/src/lib/merchant_api_tip_pickup2.c +++ b/src/lib/merchant_api_tip_pickup2.c @@ -182,11 +182,12 @@ handle_tip_pickup_finished (void *cls, hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; } break; - case MHD_HTTP_INTERNAL_SERVER_ERROR: - /* Server had an internal issue; we should retry, but this API - leaves this to the application */ + case MHD_HTTP_BAD_REQUEST: + /* Can happen if we pickup an amount that exceeds the tip... */ hr.ec = TALER_JSON_get_error_code (json); hr.hint = TALER_JSON_get_error_hint (json); + GNUNET_break (TALER_EC_MERCHANT_TIP_PICKUP_AMOUNT_EXCEEDS_TIP_REMAINING == + hr.ec); break; case MHD_HTTP_CONFLICT: /* legal, can happen if we pickup a tip twice... */ @@ -198,6 +199,12 @@ handle_tip_pickup_finished (void *cls, hr.ec = TALER_JSON_get_error_code (json); hr.hint = TALER_JSON_get_error_hint (json); break; + case MHD_HTTP_INTERNAL_SERVER_ERROR: + /* Server had an internal issue; we should retry, but this API + leaves this to the application */ + hr.ec = TALER_JSON_get_error_code (json); + hr.hint = TALER_JSON_get_error_hint (json); + break; default: /* unexpected response code */ GNUNET_break_op (0); diff --git a/src/testing/test_merchant_api_twisted.c b/src/testing/test_merchant_api_twisted.c index e134c046..c6b53049 100644 --- a/src/testing/test_merchant_api_twisted.c +++ b/src/testing/test_merchant_api_twisted.c @@ -408,7 +408,7 @@ run (void *cls, TALER_TESTING_cmd_merchant_order_abort ("pay-abort-1", merchant_url, "deposit-2", - MHD_HTTP_INTERNAL_SERVER_ERROR), + MHD_HTTP_BAD_GATEWAY), TALER_TESTING_cmd_end () }; diff --git a/src/testing/testing_api_cmd_abort_order.c b/src/testing/testing_api_cmd_abort_order.c index a0d4484d..4942fab4 100644 --- a/src/testing/testing_api_cmd_abort_order.c +++ b/src/testing/testing_api_cmd_abort_order.c @@ -189,10 +189,11 @@ abort_cb (void *cls, if (as->http_status != hr->http_status) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected response code %u (%d) to command %s\n", + "Unexpected response code %u (%d) to command `%s' (expected %u)\n", hr->http_status, (int) hr->ec, - TALER_TESTING_interpreter_get_current_label (as->is)); + TALER_TESTING_interpreter_get_current_label (as->is), + as->http_status); TALER_TESTING_FAIL (as->is); } if ( (MHD_HTTP_OK == hr->http_status) && |