Add text responses as json with msg key
This commit is contained in:
parent
f97b149376
commit
1d6e8ff037
18 changed files with 114 additions and 83 deletions
src
|
@ -42,6 +42,32 @@ endpoint_func_not_found(struct mg_connection *nc, struct http_message *hm, endpo
|
|||
|
||||
}
|
||||
|
||||
void
|
||||
endpoint_response_msg(endpoint_response_t *response, int status_code, const char *content, int content_length)
|
||||
{
|
||||
cJSON *json;
|
||||
|
||||
json = cJSON_CreateObject();
|
||||
cJSON *json_msg;
|
||||
|
||||
if(content_length)
|
||||
{
|
||||
json_msg = cJSON_CreateStringReference(content);
|
||||
}
|
||||
else
|
||||
{
|
||||
json_msg = cJSON_CreateString(content);
|
||||
}
|
||||
if(json_msg == NULL)
|
||||
{
|
||||
endpoint_response_text(response, status_code, content, content_length);
|
||||
return;
|
||||
}
|
||||
cJSON_AddItemToObject(json, "msg", json_msg);
|
||||
|
||||
endpoint_response_json(response, status_code, json);
|
||||
}
|
||||
|
||||
void
|
||||
endpoint_response_text(endpoint_response_t *response, int status_code, const char *content, int content_length)
|
||||
{
|
||||
|
@ -84,5 +110,5 @@ endpoint_response_json(endpoint_response_t *response, int status_code, const cJS
|
|||
}
|
||||
}
|
||||
|
||||
M_RESPONSE_TEXT_STATIC(LOGGER_ERR, response, 500, "failed to print json");
|
||||
M_RESPONSE_MSG(LOGGER_ERR, response, 500, "failed to print json");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue