aboutsummaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_private-get-orders.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-08-15 23:53:09 +0200
committerChristian Grothoff <christian@grothoff.org>2020-08-15 23:53:09 +0200
commit61b206043a2adc2240828ae5d6b2d1c314786253 (patch)
tree09e125384abc9cbbfe2e99debbe6fbb0dfdbbc98 /src/backend/taler-merchant-httpd_private-get-orders.c
parent5e9a041c084f70c7bb80d13b960402d30cd5e6fe (diff)
clean up GET /private/orders handling
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-get-orders.c')
-rw-r--r--src/backend/taler-merchant-httpd_private-get-orders.c53
1 files changed, 25 insertions, 28 deletions
diff --git a/src/backend/taler-merchant-httpd_private-get-orders.c b/src/backend/taler-merchant-httpd_private-get-orders.c
index 1b245b80..b98b3b76 100644
--- a/src/backend/taler-merchant-httpd_private-get-orders.c
+++ b/src/backend/taler-merchant-httpd_private-get-orders.c
@@ -39,14 +39,10 @@ struct AddOrderState
const char *instance_id;
/**
- * The result after adding the orders (0 for okay, anything else for an error).
+ * The result after adding the orders (#TALER_EC_NONE for okay, anything else for an error).
*/
- int result;
+ enum TALER_ErrorCode result;
- /**
- * In the case of an error, what message to respond with.
- */
- const char *ec_msg;
};
@@ -276,8 +272,7 @@ add_order (void *cls,
paid = false;
if (qs < 0)
{
- aos->result = 1;
- aos->ec_msg = "failed to lookup order status in database";
+ aos->result = TALER_EC_MERCHANT_PRIVATE_GET_ORDERS_STATUS_DB_LOOKUP_ERROR;
return;
}
}
@@ -304,8 +299,7 @@ add_order (void *cls,
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{
- aos->result = 1;
- aos->ec_msg = "failed to lookup order in database";
+ aos->result = TALER_EC_MERCHANT_PRIVATE_GET_ORDERS_CONTRACT_DB_LOOKUP_ERROR;
json_decref (contract_terms);
return;
}
@@ -329,8 +323,7 @@ add_order (void *cls,
spec,
NULL, NULL))
{
- aos->result = 1;
- aos->ec_msg = "failed to parse order contract terms";
+ aos->result = TALER_EC_MERCHANT_PRIVATE_GET_ORDERS_PARSE_CONTRACT_ERROR;
json_decref (contract_terms);
return;
}
@@ -350,8 +343,8 @@ add_order (void *cls,
&refund_amount);
if (0 > qs)
{
- aos->result = 1;
- aos->ec_msg = "failed to lookup order refunds in database";
+ aos->result =
+ TALER_EC_MERCHANT_PRIVATE_GET_ORDERS_REFUND_DB_LOOKUP_ERROR;
json_decref (contract_terms);
return;
}
@@ -476,13 +469,15 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh,
/* resumed from long-polling, return answer we already have
in 'hc->ctx' */
struct AddOrderState *aos = hc->ctx;
- if (0 != aos->result)
+
+ if (TALER_EC_NONE != aos->result)
{
GNUNET_break (0);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_ORDERS_GET_DB_LOOKUP_ERROR,
- aos->ec_msg);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ aos->result,
+ TALER_ErrorCode_get_hint (aos->result));
}
return TALER_MHD_reply_json_pack (connection,
MHD_HTTP_OK,
@@ -625,7 +620,7 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh,
GNUNET_assert (NULL != aos);
aos->pa = json_array ();
aos->instance_id = hc->instance->settings.id;
- aos->result = 0;
+ aos->result = TALER_EC_NONE;
GNUNET_assert (NULL != aos->pa);
{
qs = TMH_db->lookup_orders (TMH_db->cls,
@@ -633,21 +628,23 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh,
&of,
&add_order,
aos);
- if ((0 > qs) ||
- (0 != aos->result))
+ if (0 > qs)
+ {
+ aos->result =
+ TALER_EC_MERCHANT_PRIVATE_GET_ORDERS_BY_FILTER_DB_LOOKUP_ERROR;
+ }
+ if (TALER_EC_NONE != aos->result)
{
- int aos_result = aos->result;
- const char *aos_ec_msg = aos->ec_msg;
+ enum TALER_ErrorCode aos_result = aos->result;
GNUNET_break (0);
json_decref (aos->pa);
GNUNET_free (aos);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_ORDERS_GET_DB_LOOKUP_ERROR,
- 0 != aos_result ?
- aos_ec_msg :
- "failed to lookup orders in database");
+ aos_result,
+ TALER_ErrorCode_get_hint (
+ aos_result));
}
}
if ( (0 == qs) &&