summaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_private-post-transfers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-post-transfers.c')
-rw-r--r--src/backend/taler-merchant-httpd_private-post-transfers.c93
1 files changed, 55 insertions, 38 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-transfers.c b/src/backend/taler-merchant-httpd_private-post-transfers.c
index 92e3be36..178c609c 100644
--- a/src/backend/taler-merchant-httpd_private-post-transfers.c
+++ b/src/backend/taler-merchant-httpd_private-post-transfers.c
@@ -31,9 +31,9 @@
/**
* How long to wait before giving up processing with the exchange?
*/
-#define TRANSFER_TIMEOUT (GNUNET_TIME_relative_multiply ( \
- GNUNET_TIME_UNIT_SECONDS, \
- 30))
+#define TRANSFER_GENERIC_TIMEOUT (GNUNET_TIME_relative_multiply ( \
+ GNUNET_TIME_UNIT_SECONDS, \
+ 30))
/**
* How often do we retry the simple INSERT database transaction?
@@ -306,10 +306,11 @@ check_transfer (void *cls,
" s:I, s:o, s:o, s:o, s:o,"
" s:o, s:o, s:o, s:o, s:o }",
"code",
- (json_int_t) TALER_EC_POST_TRANSFERS_CONFLICTING_REPORTS,
+ (json_int_t)
+ TALER_EC_MERCHANT_PRIVATE_POST_TRANSFERS_CONFLICTING_REPORTS,
"hint",
TALER_ErrorCode_get_hint (
- TALER_EC_POST_TRANSFERS_CONFLICTING_REPORTS),
+ TALER_EC_MERCHANT_PRIVATE_POST_TRANSFERS_CONFLICTING_REPORTS),
"exchange_url",
exchange_url,
"deposit_timestamp",
@@ -404,9 +405,11 @@ check_wire_fee (struct PostTransfersContext *ptc,
ptc->response =
TALER_MHD_make_json_pack (
"{s:I, s:s, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:o}",
- "code", (json_int_t) TALER_EC_POST_TRANSFERS_JSON_BAD_WIRE_FEE,
+ "code",
+ (json_int_t) TALER_EC_MERCHANT_PRIVATE_POST_TRANSFERS_BAD_WIRE_FEE,
"hint",
- TALER_ErrorCode_get_hint (TALER_EC_POST_TRANSFERS_JSON_BAD_WIRE_FEE),
+ TALER_ErrorCode_get_hint (
+ TALER_EC_MERCHANT_PRIVATE_POST_TRANSFERS_BAD_WIRE_FEE),
"wire_fee", TALER_JSON_from_amount (wire_fee),
"execution_time", GNUNET_JSON_from_time_abs (execution_time),
"expected_wire_fee", TALER_JSON_from_amount (&expected_fee),
@@ -445,10 +448,11 @@ wire_transfer_cb (void *cls,
{
resume_transfer_with_response (
ptc,
- MHD_HTTP_FAILED_DEPENDENCY,
+ MHD_HTTP_BAD_GATEWAY,
TALER_MHD_make_json_pack (
"{s:I, s:I, s:I, s:O}",
- "code", (json_int_t) TALER_EC_POST_TRANSFERS_EXCHANGE_ERROR,
+ "code",
+ (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_UNEXPECTED_STATUS,
"exchange_code", (json_int_t) hr->ec,
"exchange_http_status", (json_int_t) hr->http_status,
"exchange_reply", hr->reply));
@@ -465,8 +469,8 @@ wire_transfer_cb (void *cls,
GNUNET_break (0);
resume_transfer_with_error (ptc,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_POST_TRANSFERS_DB_STORE_TRANSFER_ERROR,
- "could not start transaction");
+ TALER_EC_GENERIC_DB_START_FAILED,
+ NULL);
return;
}
/* Ok, exchange answer is acceptable, store it */
@@ -488,8 +492,8 @@ retry:
resume_transfer_with_error (
ptc,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_POST_TRANSFERS_DB_STORE_TRANSFER_ERROR,
- "failed to commit transaction to local database");
+ TALER_EC_GENERIC_DB_COMMIT_FAILED,
+ NULL);
return;
}
if (0 <= qs)
@@ -503,8 +507,8 @@ retry:
resume_transfer_with_error (
ptc,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_POST_TRANSFERS_DB_STORE_TRANSFER_ERROR,
- "repeated serialization failures trying to commit transaction to local database");
+ TALER_EC_GENERIC_DB_SOFT_FAILURE,
+ NULL);
return;
}
@@ -538,20 +542,33 @@ process_transfer_with_exchange (void *cls,
(void) payto_uri;
(void) exchange_trusted;
ptc->fo = NULL;
- if (MHD_HTTP_OK != hr->http_status)
+ if (NULL == hr)
+ {
+ resume_transfer_with_response (
+ ptc,
+ MHD_HTTP_GATEWAY_TIMEOUT,
+ TALER_MHD_make_json_pack (
+ "{s:s, s:I}"
+ "hint", TALER_ErrorCode_get_hint (
+ TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT),
+ "code",
+ (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT));
+ return;
+ }
+ if (NULL == eh)
{
/* The request failed somehow */
GNUNET_break_op (0);
resume_transfer_with_response (
ptc,
- MHD_HTTP_FAILED_DEPENDENCY,
+ MHD_HTTP_BAD_GATEWAY,
TALER_MHD_make_json_pack (
(NULL != hr->reply)
? "{s:s, s:I, s:I, s:I, s:O}"
: "{s:s, s:I, s:I, s:I}",
"hint", TALER_ErrorCode_get_hint (
- TALER_EC_POST_TRANSFERS_EXCHANGE_KEYS_FAILURE),
- "code", (json_int_t) TALER_EC_POST_TRANSFERS_EXCHANGE_KEYS_FAILURE,
+ TALER_EC_MERCHANT_GENERIC_EXCHANGE_CONNECT_FAILURE),
+ "code", (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_CONNECT_FAILURE,
"exchange_http_status", (json_int_t) hr->http_status,
"exchange_code", (json_int_t) hr->ec,
"exchange_reply", hr->reply));
@@ -567,9 +584,9 @@ process_transfer_with_exchange (void *cls,
{
GNUNET_break (0);
resume_transfer_with_error (ptc,
- MHD_HTTP_FAILED_DEPENDENCY,
- TALER_EC_POST_TRANSFERS_EXCHANGE_KEYS_FAILURE,
- "failed to get keys");
+ MHD_HTTP_BAD_GATEWAY,
+ TALER_EC_MERCHANT_GENERIC_EXCHANGE_KEYS_FAILURE,
+ NULL);
return;
}
ptc->master_pub = keys->master_pub;
@@ -584,7 +601,7 @@ process_transfer_with_exchange (void *cls,
GNUNET_break (0);
resume_transfer_with_error (ptc,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_POST_TRANSFERS_REQUEST_ERROR,
+ TALER_EC_MERCHANT_PRIVATE_POST_TRANSFERS_REQUEST_ERROR,
"failed to run GET /transfers/ on exchange");
}
}
@@ -631,8 +648,8 @@ verify_exchange_claim_cb (void *cls,
GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
ptc->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
ptc->response
- = TALER_MHD_make_error (TALER_EC_POST_TRANSFERS_DB_FETCH_DEPOSIT_ERROR,
- "failed to obtain deposit data from local database");
+ = TALER_MHD_make_error (TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "deposit by contract and coin");
return;
}
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
@@ -651,8 +668,8 @@ verify_exchange_claim_cb (void *cls,
GNUNET_break (0);
ptc->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
ptc->response =
- TALER_MHD_make_error (TALER_EC_POST_TRANSFERS_DB_INTERNAL_LOGIC_ERROR,
- "internal logic error");
+ TALER_MHD_make_error (TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
+ "check_transfer_result must not be NULL");
return;
}
if (GNUNET_SYSERR == ptc->check_transfer_result)
@@ -807,9 +824,9 @@ handle_transfer_timeout (void *cls)
ptc->wdh = NULL;
}
resume_transfer_with_error (ptc,
- MHD_HTTP_SERVICE_UNAVAILABLE,
- TALER_EC_POST_TRANSFERS_EXCHANGE_TIMEOUT,
- "exchange not reachable");
+ MHD_HTTP_GATEWAY_TIMEOUT,
+ TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT,
+ NULL);
}
@@ -926,8 +943,8 @@ queue:
GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_POST_TRANSFERS_DB_LOOKUP_ERROR,
- NULL);
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "transfer");
}
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
goto fetch;
@@ -981,8 +998,8 @@ queue:
GNUNET_CONTAINER_multihashmap_destroy (map);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_POST_TRANSFERS_DB_LOOKUP_ERROR,
- NULL);
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "transfer summary");
}
deposit_sums = json_array ();
@@ -1020,8 +1037,8 @@ fetch:
GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_POST_TRANSFERS_DB_STORE_ERROR,
- NULL);
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "transfer");
}
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
{
@@ -1042,7 +1059,7 @@ fetch:
ptc->hc->instance->settings.id);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_NOT_FOUND,
- TALER_EC_POST_TRANSFERS_ACCOUNT_NOT_FOUND,
+ TALER_EC_MERCHANT_PRIVATE_POST_TRANSFERS_ACCOUNT_NOT_FOUND,
ptc->payto_uri);
}
}
@@ -1059,7 +1076,7 @@ fetch:
&process_transfer_with_exchange,
ptc);
ptc->timeout_task
- = GNUNET_SCHEDULER_add_delayed (TRANSFER_TIMEOUT,
+ = GNUNET_SCHEDULER_add_delayed (TRANSFER_GENERIC_TIMEOUT,
&handle_transfer_timeout,
ptc);
return MHD_YES;