summaryrefslogtreecommitdiff
path: root/src/lib/exchange_api_recoup.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-04-05 22:05:38 +0200
committerChristian Grothoff <christian@grothoff.org>2020-04-05 22:05:38 +0200
commitbf8c5982a2e79f0b5198a0033dd41e9702d093f9 (patch)
tree93b62feb9b7e24ae3d4f73b1a5f883a8fc368bfe /src/lib/exchange_api_recoup.c
parent5059da7108fb2d65fc3844ffe695574c532f8dff (diff)
downloadexchange-bf8c5982a2e79f0b5198a0033dd41e9702d093f9.tar.gz
exchange-bf8c5982a2e79f0b5198a0033dd41e9702d093f9.tar.bz2
exchange-bf8c5982a2e79f0b5198a0033dd41e9702d093f9.zip
make exchange API more uniform in how information is returned
Diffstat (limited to 'src/lib/exchange_api_recoup.c')
-rw-r--r--src/lib/exchange_api_recoup.c69
1 files changed, 40 insertions, 29 deletions
diff --git a/src/lib/exchange_api_recoup.c b/src/lib/exchange_api_recoup.c
index a3416b5bc..484d27536 100644
--- a/src/lib/exchange_api_recoup.c
+++ b/src/lib/exchange_api_recoup.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2017 Taler Systems SA
+ Copyright (C) 2017-2020 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -112,6 +112,10 @@ process_recoup_response (const struct TALER_EXCHANGE_RecoupHandle *ph,
GNUNET_JSON_spec_fixed_auto ("old_coin_pub", &old_coin_pub),
GNUNET_JSON_spec_end ()
};
+ struct TALER_EXCHANGE_HttpResponse hr = {
+ .reply = json,
+ .http_status = MHD_HTTP_OK
+ };
if (GNUNET_OK !=
GNUNET_JSON_parse (json,
@@ -127,11 +131,9 @@ process_recoup_response (const struct TALER_EXCHANGE_RecoupHandle *ph,
return GNUNET_SYSERR;
}
ph->cb (ph->cb_cls,
- MHD_HTTP_OK,
- TALER_EC_NONE,
+ &hr,
ph->was_refreshed ? NULL : &reserve_pub,
- ph->was_refreshed ? &old_coin_pub : NULL,
- json);
+ ph->was_refreshed ? &old_coin_pub : NULL);
return GNUNET_OK;
}
@@ -151,23 +153,25 @@ handle_recoup_finished (void *cls,
{
struct TALER_EXCHANGE_RecoupHandle *ph = cls;
const json_t *j = response;
- enum TALER_ErrorCode ec;
+ struct TALER_EXCHANGE_HttpResponse hr = {
+ .reply = j,
+ .http_status = (unsigned int) response_code
+ };
ph->job = NULL;
switch (response_code)
{
case 0:
- ec = TALER_EC_INVALID_RESPONSE;
+ hr.ec = TALER_EC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
- ec = TALER_EC_NONE;
if (GNUNET_OK !=
process_recoup_response (ph,
j))
{
GNUNET_break_op (0);
- ec = TALER_EC_RECOUP_REPLY_MALFORMED;
- response_code = 0;
+ hr.ec = TALER_EC_RECOUP_REPLY_MALFORMED;
+ hr.http_status = 0;
break;
}
TALER_EXCHANGE_recoup_cancel (ph);
@@ -175,7 +179,8 @@ handle_recoup_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:
{
@@ -195,15 +200,18 @@ handle_recoup_finished (void *cls,
&total))
{
GNUNET_break_op (0);
- response_code = 0;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_RECOUP_REPLY_MALFORMED;
+ }
+ else
+ {
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
}
- ec = TALER_JSON_get_error_code (j);
ph->cb (ph->cb_cls,
- response_code,
- ec,
- NULL,
+ &hr,
NULL,
- j);
+ NULL);
TALER_EXCHANGE_recoup_cancel (ph);
return;
}
@@ -211,39 +219,42 @@ handle_recoup_finished (void *cls,
/* 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_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);
+ 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);
+ "Unexpected response code %u/%d\n",
+ (unsigned int) response_code,
+ (int) hr.ec);
GNUNET_break (0);
- response_code = 0;
break;
}
ph->cb (ph->cb_cls,
- response_code,
- ec,
- NULL,
+ &hr,
NULL,
- j);
+ NULL);
TALER_EXCHANGE_recoup_cancel (ph);
}