From bf8c5982a2e79f0b5198a0033dd41e9702d093f9 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 5 Apr 2020 22:05:38 +0200 Subject: make exchange API more uniform in how information is returned --- src/lib/exchange_api_refund.c | 47 +++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'src/lib/exchange_api_refund.c') diff --git a/src/lib/exchange_api_refund.c b/src/lib/exchange_api_refund.c index 826c39b17..81127c5a7 100644 --- a/src/lib/exchange_api_refund.c +++ b/src/lib/exchange_api_refund.c @@ -145,13 +145,16 @@ handle_refund_finished (void *cls, struct TALER_ExchangePublicKeyP exchange_pub; struct TALER_ExchangePublicKeyP *ep = NULL; const json_t *j = response; - enum TALER_ErrorCode ec; + struct TALER_EXCHANGE_HttpResponse hr = { + .reply = j, + .http_status = (unsigned int) response_code + }; rh->job = NULL; switch (response_code) { case 0: - ec = TALER_EC_INVALID_RESPONSE; + hr.ec = TALER_EC_INVALID_RESPONSE; break; case MHD_HTTP_OK: if (GNUNET_OK != @@ -160,67 +163,71 @@ handle_refund_finished (void *cls, &exchange_pub)) { GNUNET_break_op (0); - response_code = 0; - ec = TALER_EC_REFUND_INVALID_SIGNATURE_BY_EXCHANGE; + hr.http_status = 0; + hr.ec = TALER_EC_REFUND_INVALID_SIGNATURE_BY_EXCHANGE; } else { ep = &exchange_pub; - ec = TALER_EC_NONE; } break; case MHD_HTTP_BAD_REQUEST: /* This should never happen, either us or the exchange is buggy (or API version conflict); just pass JSON reply to the application */ - ec = TALER_JSON_get_error_code (j); + hr.ec = TALER_JSON_get_error_code (j); + hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_FORBIDDEN: /* Nothing really to verify, exchange says one of the signatures is invalid; as we checked them, this should never happen, we should pass the JSON reply to the application */ - ec = TALER_JSON_get_error_code (j); + hr.ec = TALER_JSON_get_error_code (j); + hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_NOT_FOUND: /* Nothing really to verify, this should never happen, we should pass the JSON reply to the application */ - ec = TALER_JSON_get_error_code (j); + hr.ec = TALER_JSON_get_error_code (j); + hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_GONE: /* Kind of normal: the money was already sent to the merchant (it was too late for the refund). */ - ec = TALER_JSON_get_error_code (j); + hr.ec = TALER_JSON_get_error_code (j); + hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_PRECONDITION_FAILED: /* Client request was inconsistent; might be a currency mismatch problem. */ - ec = TALER_JSON_get_error_code (j); + hr.ec = TALER_JSON_get_error_code (j); + hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_CONFLICT: /* Two refund requests were made about the same deposit, but carrying different refund transaction ids. */ - ec = TALER_JSON_get_error_code (j); + hr.ec = TALER_JSON_get_error_code (j); + hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_INTERNAL_SERVER_ERROR: /* Server had an internal issue; we should retry, but this API leaves this to the application */ - ec = TALER_JSON_get_error_code (j); + hr.ec = TALER_JSON_get_error_code (j); + hr.hint = TALER_JSON_get_error_hint (j); break; default: /* unexpected response code */ - ec = TALER_JSON_get_error_code (j); + GNUNET_break_op (0); + hr.ec = TALER_JSON_get_error_code (j); + hr.hint = TALER_JSON_get_error_hint (j); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d\n", (unsigned int) response_code, - ec); - GNUNET_break (0); - response_code = 0; + hr.ec); break; } rh->cb (rh->cb_cls, - response_code, - ec, - ep, - j); + &hr, + ep); TALER_EXCHANGE_refund_cancel (rh); } -- cgit v1.2.3