From ea5c1233f13ad3128207b6b84401d8638dbc43e5 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 8 Jul 2015 09:40:13 +0200 Subject: nicer error reporting --- src/mint/taler-mint-httpd_deposit.c | 38 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) (limited to 'src/mint/taler-mint-httpd_deposit.c') diff --git a/src/mint/taler-mint-httpd_deposit.c b/src/mint/taler-mint-httpd_deposit.c index c1495c817..7d9ace00d 100644 --- a/src/mint/taler-mint-httpd_deposit.c +++ b/src/mint/taler-mint-httpd_deposit.c @@ -234,7 +234,11 @@ TMH_DEPOSIT_handler_deposit (struct TMH_RequestHandler *rh, json_t *wire; int res; struct TALER_Amount amount; - json_t *f; + struct TMH_PARSE_FieldSpecification spec[] = { + TMH_PARSE_member_object ("wire", &wire), + TMH_PARSE_member_amount ("f", &amount), + TMH_PARSE_MEMBER_END + }; res = TMH_PARSE_post_json (connection, connection_cls, @@ -245,39 +249,19 @@ TMH_DEPOSIT_handler_deposit (struct TMH_RequestHandler *rh, return MHD_NO; if ( (GNUNET_NO == res) || (NULL == json) ) return MHD_YES; - if (-1 == json_unpack (json, - "{s:o, s:o}", - "wire", &wire, - "f", &f)) - { - GNUNET_break_op (0); - json_decref (json); - return TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{s:s}", - "error", "Bad format"); - } - res = TMH_PARSE_amount_json (connection, - f, - &amount); - json_decref (f); - if (GNUNET_SYSERR == res) - { - json_decref (wire); - json_decref (json); - return MHD_NO; - } - if (GNUNET_NO == res) + res = TMH_PARSE_json_data (connection, + json, + spec); + if (GNUNET_OK != res) { - json_decref (wire); json_decref (json); - return MHD_YES; + return (GNUNET_NO == res) ? MHD_YES : MHD_NO; } res = parse_and_handle_deposit_request (connection, json, &amount, wire); - json_decref (wire); + TMH_PARSE_release_data (spec); json_decref (json); return res; } -- cgit v1.2.3