FS-9952: Add blade rpc error response creation

This commit is contained in:
colm 2017-02-15 21:17:13 -05:00 committed by Mike Jerris
parent aeff38c165
commit 8e417220d3
3 changed files with 33 additions and 1 deletions

View File

@ -811,6 +811,31 @@ KS_DECLARE(ks_rpcmessageid_t) blade_rpc_create_response(cJSON *request,
return msgid;
}
KS_DECLARE(ks_rpcmessageid_t) blade_rpc_create_errorresponse(cJSON *request,
cJSON **errorP,
cJSON **responseP)
{
ks_rpcmessageid_t msgid = blade_rpc_create_response(request, NULL, responseP);
if (msgid) {
if (errorP) {
if (*errorP) {
cJSON_AddItemToObject(*responseP, "error", *errorP);
}
else {
cJSON *error = cJSON_CreateObject();
cJSON_AddItemToObject(*responseP, "error", error);
*errorP = error;
}
}
}
return msgid;
}
const char BLADE_JRPC_METHOD[] = "method";
const char BLADE_JRPC_ID[] = "id";
const char BLADE_JRPC_FIELDS[] = "blade";

View File

@ -127,6 +127,10 @@ KS_DECLARE(ks_rpcmessageid_t) blade_rpc_create_response(cJSON *request,
cJSON **reply,
cJSON **response);
KS_DECLARE(ks_rpcmessageid_t) blade_rpc_create_errorresponse(cJSON *request,
cJSON **reply,
cJSON **response);
KS_DECLARE(ks_status_t) blade_rpc_parse_message(cJSON *message,
char **namespace,
char **method,

View File

@ -286,7 +286,7 @@ KS_DECLARE(ks_rpcmessageid_t) ks_rpcmessage_create_errorresponse(
cJSON **errorP,
cJSON **responseP)
{
ks_rpcmessageid_t msgid = ks_rpcmessage_new_response(request, errorP, responseP);
ks_rpcmessageid_t msgid = ks_rpcmessage_new_response(request, NULL, responseP);
cJSON *respmsg = *responseP;
if (msgid) {
@ -296,6 +296,9 @@ KS_DECLARE(ks_rpcmessageid_t) ks_rpcmessage_create_errorresponse(
*errorP = error;
cJSON_AddItemToObject(respmsg, ERROR, error);
}
else if (errorP && *errorP) {
cJSON_AddItemToObject(*responseP, ERROR, *errorP);
}
}
return msgid;