From 9d7d9badfcf1f82af34d82f6049a8f03fc96db56 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 10 Aug 2017 13:31:34 +0200 Subject: [PATCH] api: allow failed actions to return a response --- lib/api/session.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/api/session.c b/lib/api/session.c index aa96195b8..ee27f4064 100644 --- a/lib/api/session.c +++ b/lib/api/session.c @@ -64,7 +64,8 @@ int api_session_run_command(struct api_session *s, json_t *json_in, json_t **jso char *id; struct plugin *p; - json_t *json_args = NULL, *json_resp; + json_t *json_args = NULL; + json_t *json_resp = NULL; ret = json_unpack(json_in, "{ s: s, s: s, s?: o }", "action", &action, @@ -99,10 +100,12 @@ int api_session_run_command(struct api_session *s, json_t *json_in, json_t **jso "code", ret, "error", "command failed"); else - *json_out = json_pack("{ s: s, s: s, s: o }", + *json_out = json_pack("{ s: s, s: s }", "action", action, - "id", id, - "response", json_resp); + "id", id); + + if (json_resp) + json_object_set(*json_out, "response", json_resp); out: debug(LOG_API, "API request completed with code: %d", ret);