gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-merchant] branch master updated: only log things as ERROR that ar


From: gnunet
Subject: [taler-merchant] branch master updated: only log things as ERROR that are actually ERRORs; return 502 instead of 500 on abort failure due to malformed exchange reply
Date: Mon, 18 Jan 2021 11:58:03 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new cd47c8e0 only log things as ERROR that are actually ERRORs; return 502 
instead of 500 on abort failure due to malformed exchange reply
cd47c8e0 is described below

commit cd47c8e0afb66f2d9053082940f208347551b3a8
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon Jan 18 11:58:00 2021 +0100

    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 ++++++++++++----
 src/lib/merchant_api_delete_reserve.c                   |  4 ++++
 src/lib/merchant_api_tip_pickup2.c                      | 13 ++++++++++---
 src/testing/test_merchant_api_twisted.c                 |  2 +-
 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) &&

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]