diff options
Diffstat (limited to 'src/backend/taler-merchant-httpd_post-orders-ID-abort.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_post-orders-ID-abort.c | 91 |
1 files changed, 50 insertions, 41 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 cfb5bb72..4f6b8667 100644 --- a/src/backend/taler-merchant-httpd_post-orders-ID-abort.c +++ b/src/backend/taler-merchant-httpd_post-orders-ID-abort.c @@ -32,8 +32,9 @@ /** * How long to wait before giving up processing with the exchange? */ -#define ABORT_TIMEOUT (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ - 30)) +#define ABORT_GENERIC_TIMEOUT (GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, \ + 30)) /** * How often do we retry the (complex!) database transaction? @@ -349,7 +350,7 @@ generate_success_response (struct AbortContext *ac) GNUNET_break (0); resume_abort_with_error (ac, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_JSON_ALLOCATION_FAILURE, + TALER_EC_GENERIC_JSON_ALLOCATION_FAILURE, "could not create JSON array"); return; } @@ -386,7 +387,7 @@ generate_success_response (struct AbortContext *ac) GNUNET_break (0); resume_abort_with_error (ac, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_JSON_ALLOCATION_FAILURE, + TALER_EC_GENERIC_JSON_ALLOCATION_FAILURE, "could not create JSON array"); return; } @@ -518,27 +519,35 @@ process_abort_with_exchange (void *cls, (void) exchange_trusted; ac->fo = NULL; GNUNET_assert (GNUNET_YES == ac->suspended); - if (MHD_HTTP_OK != hr->http_status) + if (NULL == hr) { - /* The request failed somehow */ - GNUNET_break_op (0); resume_abort_with_response ( ac, - MHD_HTTP_FAILED_DEPENDENCY, + MHD_HTTP_GATEWAY_TIMEOUT, 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}", + "{s:s, s:I}", "hint", - TALER_ErrorCode_get_hint (TALER_EC_ABORT_EXCHANGE_KEYS_FAILURE), + TALER_ErrorCode_get_hint ( + TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT), "code", - (json_int_t) TALER_EC_ABORT_EXCHANGE_KEYS_FAILURE, - "exchange_http_status", - (json_int_t) hr->http_status, - "exchange_code", - (json_int_t) hr->ec, - "exchange_reply", - hr->reply)); + (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT)); + return; + } + if (NULL == exchange_handle) + { + /* The request failed somehow */ + GNUNET_break_op (0); + resume_abort_with_response ( + ac, + MHD_HTTP_BAD_GATEWAY, + TALER_MHD_make_json_pack ( + "{s:s, s:I, s:I, s:I, s:O?}", + "hint", TALER_ErrorCode_get_hint ( + 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)); return; } /* Initiate refund operation for all coins of @@ -569,7 +578,7 @@ process_abort_with_exchange (void *cls, GNUNET_break_op (0); resume_abort_with_error (ac, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_ABORT_EXCHANGE_REFUND_FAILED, + TALER_EC_MERCHANT_POST_ORDERS_ID_ABORT_EXCHANGE_REFUND_FAILED, "Failed to start refund with exchange"); return; } @@ -615,7 +624,7 @@ find_next_exchange (struct AbortContext *ac) GNUNET_break (0); resume_abort_with_error (ac, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_ABORT_EXCHANGE_LOOKUP_FAILED, + TALER_EC_MERCHANT_POST_ORDERS_ID_ABORT_EXCHANGE_LOOKUP_FAILED, "Failed to lookup exchange by URL"); return; } @@ -691,8 +700,8 @@ refund_coins (void *cls, GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); resume_abort_with_error (ac, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_ABORT_DB_STORE_ABORT_ERROR, - "Merchant database error storing abort-refund"); + TALER_EC_GENERIC_DB_STORE_FAILED, + "refund_coin"); return; } } /* for all coins */ @@ -716,8 +725,8 @@ begin_transaction (struct AbortContext *ac) GNUNET_break (0); resume_abort_with_error (ac, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_ABORT_DB_STORE_TRANSACTION_ERROR, - "Soft merchant database error: retry counter exceeded"); + TALER_EC_GENERIC_DB_SOFT_FAILURE, + NULL); return; } GNUNET_assert (GNUNET_YES == ac->suspended); @@ -731,8 +740,8 @@ begin_transaction (struct AbortContext *ac) GNUNET_break (0); resume_abort_with_error (ac, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_ABORT_DB_FETCH_TRANSACTION_ERROR, - "Merchant database error (could not begin transaction)"); + TALER_EC_GENERIC_DB_START_FAILED, + NULL); return; } @@ -763,14 +772,14 @@ begin_transaction (struct AbortContext *ac) GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); resume_abort_with_error (ac, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_ABORT_DB_FETCH_TRANSACTION_ERROR, - "Merchant database error"); + TALER_EC_GENERIC_DB_FETCH_FAILED, + "order status"); return; case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: TMH_db->rollback (TMH_db->cls); resume_abort_with_error (ac, MHD_HTTP_NOT_FOUND, - TALER_EC_ABORT_CONTRACT_NOT_FOUND, + TALER_EC_MERCHANT_POST_ORDERS_ID_ABORT_CONTRACT_NOT_FOUND, "Could not find contract"); return; case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: @@ -780,7 +789,7 @@ begin_transaction (struct AbortContext *ac) TMH_db->rollback (TMH_db->cls); resume_abort_with_error (ac, MHD_HTTP_PRECONDITION_FAILED, - TALER_EC_ABORT_REFUND_REFUSED_PAYMENT_COMPLETE, + TALER_EC_MERCHANT_POST_ORDERS_ID_ABORT_REFUND_REFUSED_PAYMENT_COMPLETE, "Payment was complete, refusing to abort"); return; } @@ -792,7 +801,7 @@ begin_transaction (struct AbortContext *ac) GNUNET_break_op (0); resume_abort_with_error (ac, MHD_HTTP_FORBIDDEN, - TALER_EC_ABORT_CONTRACT_HASH_MISSMATCH, + TALER_EC_MERCHANT_POST_ORDERS_ID_ABORT_CONTRACT_HASH_MISSMATCH, "Provided hash does not match order on file"); return; } @@ -816,8 +825,8 @@ begin_transaction (struct AbortContext *ac) GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); resume_abort_with_error (ac, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_ABORT_DB_FETCH_TRANSACTION_ERROR, - "Merchant database error"); + TALER_EC_GENERIC_DB_FETCH_FAILED, + "deposits"); return; } @@ -832,8 +841,8 @@ begin_transaction (struct AbortContext *ac) } resume_abort_with_error (ac, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_ABORT_DB_STORE_ABORT_ERROR, - "Merchant database error: could not commit"); + TALER_EC_GENERIC_DB_COMMIT_FAILED, + NULL); return; } @@ -889,7 +898,7 @@ parse_abort (struct MHD_Connection *connection, GNUNET_JSON_parse_free (spec); return TALER_MHD_reply_with_error (connection, MHD_HTTP_BAD_REQUEST, - TALER_EC_ABORT_COINS_ARRAY_EMPTY, + TALER_EC_MERCHANT_POST_ORDERS_ID_ABORT_COINS_ARRAY_EMPTY, "coins"); } /* note: 1 coin = 1 deposit confirmation expected */ @@ -957,9 +966,9 @@ handle_abort_timeout (void *cls) ac->fo = NULL; } resume_abort_with_error (ac, - MHD_HTTP_REQUEST_TIMEOUT, - TALER_EC_ABORT_EXCHANGE_TIMEOUT, - "likely the exchange did not reply quickly enough"); + MHD_HTTP_GATEWAY_TIMEOUT, + TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT, + NULL); } @@ -1023,7 +1032,7 @@ TMH_post_orders_ID_abort (const struct TMH_RequestHandler *rh, ac->suspended = GNUNET_YES; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Suspending abort handling while working with the exchange\n"); - ac->timeout_task = GNUNET_SCHEDULER_add_delayed (ABORT_TIMEOUT, + ac->timeout_task = GNUNET_SCHEDULER_add_delayed (ABORT_GENERIC_TIMEOUT, &handle_abort_timeout, ac); begin_transaction (ac); |