From cd47c8e0afb66f2d9053082940f208347551b3a8 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 18 Jan 2021 11:58:00 +0100 Subject: only log things as ERROR that are actually ERRORs; return 502 instead of 500 on abort failure due to malformed exchange reply --- src/backend/taler-merchant-httpd_post-orders-ID-abort.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/backend') 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)); -- cgit v1.2.3