-introduce new convenience macro

This commit is contained in:
Christian Grothoff 2021-12-31 11:23:42 +01:00
parent 5cd2bc5de3
commit b49fac3d58
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
2 changed files with 13 additions and 4 deletions

View File

@ -249,6 +249,17 @@ TALER_MHD_make_json_pack (const char *fmt,
TALER_MHD_make_json_steal (GNUNET_JSON_PACK (__VA_ARGS__)) TALER_MHD_make_json_steal (GNUNET_JSON_PACK (__VA_ARGS__))
/**
* Pack Taler error code @a ec and associated hint into a
* JSON object.
*
* @param ec error code to pack
* @return packer array entries (two!)
*/
#define TALER_MHD_PACK_EC(ec) \
GNUNET_JSON_pack_uint64 ("code", ec), \
GNUNET_JSON_pack_string ("hint", TALER_ErrorCode_get_hint (ec))
/** /**
* Create a response indicating an internal error. * Create a response indicating an internal error.
* *

View File

@ -371,8 +371,7 @@ TALER_MHD_make_error (enum TALER_ErrorCode ec,
const char *detail) const char *detail)
{ {
return TALER_MHD_MAKE_JSON_PACK ( return TALER_MHD_MAKE_JSON_PACK (
GNUNET_JSON_pack_uint64 ("code", ec), TALER_MHD_PACK_EC (ec),
GNUNET_JSON_pack_string ("hint", TALER_ErrorCode_get_hint (ec)),
GNUNET_JSON_pack_allow_null ( GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_string ("detail", detail))); GNUNET_JSON_pack_string ("detail", detail)));
} }
@ -387,8 +386,7 @@ TALER_MHD_reply_with_error (struct MHD_Connection *connection,
return TALER_MHD_REPLY_JSON_PACK ( return TALER_MHD_REPLY_JSON_PACK (
connection, connection,
http_status, http_status,
GNUNET_JSON_pack_uint64 ("code", ec), TALER_MHD_PACK_EC (ec),
GNUNET_JSON_pack_string ("hint", TALER_ErrorCode_get_hint (ec)),
GNUNET_JSON_pack_allow_null ( GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_string ("detail", detail))); GNUNET_JSON_pack_string ("detail", detail)));
} }