merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 7d83b800d2aeb814032ae69007290f69aace42c3
parent 49bb51daf5486817c3adc8a63137de1ec9d98589
Author: Christian Grothoff <christian@grothoff.org>
Date:   Mon, 18 May 2020 19:28:45 +0200

better error handling

Diffstat:
Msrc/backend/taler-merchant-httpd_exchanges.c | 2+-
Msrc/backend/taler-merchant-httpd_private-post-reserves.c | 38+++++++++++++++++++++++++++++++-------
2 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_exchanges.c b/src/backend/taler-merchant-httpd_exchanges.c @@ -656,7 +656,7 @@ handle_wire_data (void *cls, { fo->fc (fo->fc_cls, hr, - NULL, + exchange->conn, NULL, NULL, GNUNET_NO); diff --git a/src/backend/taler-merchant-httpd_private-post-reserves.c b/src/backend/taler-merchant-httpd_private-post-reserves.c @@ -85,6 +85,16 @@ struct PostReserveContext struct GNUNET_TIME_Absolute reserve_expiration; /** + * Which HTTP status should we return? + */ + unsigned int http_status; + + /** + * Which error code should we return? + */ + enum TALER_ErrorCode ec; + + /** * Are we suspended? */ bool suspended; @@ -175,14 +185,28 @@ handle_exchange (void *cls, rc->suspended = false; MHD_resume_connection (rc->connection); + if (NULL == hr) + { + rc->ec = TALER_EC_TIMEOUT; + rc->http_status = MHD_HTTP_REQUEST_TIMEOUT; + return; + } keys = TALER_EXCHANGE_get_keys (eh); - if ( (NULL != keys) && - (NULL != payto_uri) ) + if (NULL == keys) + { + rc->ec = TALER_EC_KEYS_INVALID; + rc->http_status = MHD_HTTP_FAILED_DEPENDENCY; + return; + } + if (NULL == payto_uri) { - rc->reserve_expiration - = GNUNET_TIME_relative_to_absolute (keys->reserve_closing_delay); - rc->payto_uri = GNUNET_strdup (payto_uri); + rc->ec = TALER_EC_RESERVES_POST_UNSUPPORTED_WIRE_METHOD; + rc->http_status = MHD_HTTP_CONFLICT; + return; } + rc->reserve_expiration + = GNUNET_TIME_relative_to_absolute (keys->reserve_closing_delay); + rc->payto_uri = GNUNET_strdup (payto_uri); } @@ -249,8 +273,8 @@ TMH_private_post_reserves (const struct TMH_RequestHandler *rh, if (NULL == rc->payto_uri) { return TALER_MHD_reply_with_error (connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_RESERVES_POST_UNSUPPORTED_WIRE_METHOD, + rc->http_status, + rc->ec, "Exchange does not support wire method"); } {