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_refreshes_reveal.c | 44 +++++++++++++++++---------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'src/lib/exchange_api_refreshes_reveal.c') diff --git a/src/lib/exchange_api_refreshes_reveal.c b/src/lib/exchange_api_refreshes_reveal.c index f07dc9047..f8071f5c5 100644 --- a/src/lib/exchange_api_refreshes_reveal.c +++ b/src/lib/exchange_api_refreshes_reveal.c @@ -202,13 +202,16 @@ handle_refresh_reveal_finished (void *cls, { struct TALER_EXCHANGE_RefreshesRevealHandle *rrh = cls; const json_t *j = response; - enum TALER_ErrorCode ec; + struct TALER_EXCHANGE_HttpResponse hr = { + .reply = j, + .http_status = MHD_HTTP_OK + }; rrh->job = NULL; switch (response_code) { case 0: - ec = TALER_EC_INVALID_RESPONSE; + hr.ec = TALER_EC_INVALID_RESPONSE; break; case MHD_HTTP_OK: { @@ -221,19 +224,16 @@ handle_refresh_reveal_finished (void *cls, sigs); if (GNUNET_OK != ret) { - response_code = 0; - ec = TALER_EC_REVEAL_REPLY_MALFORMED; + hr.http_status = 0; + hr.ec = TALER_EC_REVEAL_REPLY_MALFORMED; } else { - ec = TALER_EC_NONE; rrh->reveal_cb (rrh->reveal_cb_cls, - MHD_HTTP_OK, - ec, + &hr, rrh->md->num_fresh_coins, rrh->md->fresh_coins[rrh->noreveal_index], - sigs, - j); + sigs); rrh->reveal_cb = NULL; } for (unsigned int i = 0; imd->num_fresh_coins; i++) @@ -245,37 +245,39 @@ handle_refresh_reveal_finished (void *cls, 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_CONFLICT: /* Nothing really to verify, exchange says our reveal is inconsistent with our commitment, so either side is buggy; 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_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 */ + 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\n", - (unsigned int) response_code); - GNUNET_break (0); - response_code = 0; - ec = TALER_JSON_get_error_code (j); + "Unexpected response code %u/%d\n", + (unsigned int) response_code, + (int) hr.ec); break; } if (NULL != rrh->reveal_cb) rrh->reveal_cb (rrh->reveal_cb_cls, - response_code, - ec, + &hr, 0, NULL, - NULL, - j); + NULL); TALER_EXCHANGE_refreshes_reveal_cancel (rrh); } -- cgit v1.2.3