Skip to content

Commit

Permalink
janssonrpc-c: allow null json error property in rpc response
Browse files Browse the repository at this point in the history
If the JSON RPC response contains an error property, check to see if it is a json_null or not before flagging the response as an error.

(cherry picked from commit 92ba30d)
  • Loading branch information
Jason Newman authored and miconda committed Sep 8, 2015
1 parent 23bca85 commit 5056765
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions modules/janssonrpc-c/janssonrpc_io.c
Expand Up @@ -587,17 +587,20 @@ int handle_response(json_t* response)
return_obj = json_object();

json_t* error = json_object_get(response, "error");
// if the error value is null, we don't care
bool _error = error && (json_typeof(error) != JSON_NULL);

json_t* result = json_object_get(response, "result");

if(error) {
if(_error) {
json_object_set(return_obj, "error", error);
}

if(result) {
json_object_set(return_obj, "result", result);
}

if ((!result && !error) || (result && error)) {
if ((!result && !_error) || (result && _error)) {
WARN("bad response\n");
internal = internal_error(JRPC_ERR_BAD_RESP, req->payload);
json_object_update(return_obj, internal);
Expand All @@ -621,7 +624,7 @@ int handle_response(json_t* response)
goto free_and_end;
}

if(error) {
if(_error) {
// get code from error
json_t* _code = json_object_get(error, "code");
if(_code) {
Expand Down

0 comments on commit 5056765

Please sign in to comment.