fix: 504 return code and relay_schedule junction

This commit is contained in:
Tobias Reisinger 2020-05-19 18:03:44 +02:00
parent c370ab6fea
commit 6050f1cc5f
2 changed files with 14 additions and 16 deletions

View file

@ -226,24 +226,18 @@ api_v1_controllers_STR_relays_INT_PUT(struct mg_connection *c, endpoint_args_t *
cJSON_Delete(json);
json = relay_to_json(relay);
int result = command_set_relay_schedule(relay);
int status_code = 200;
if(result)
{
status_code = 504;
}
command_set_relay_schedule(relay);
char *json_str = cJSON_Print(json);
if (json_str == NULL)
{
LOG_ERROR("failed to print relay json\n");
mg_send_head(c, status_code, 2, "Content-Type: application/json\r\n" STANDARD_HEADERS);
mg_send_head(c, 200, 2, "Content-Type: application/json\r\n" STANDARD_HEADERS);
mg_printf(c, "{}");
}
else
{
mg_send_head(c, status_code, strlen(json_str), "Content-Type: application/json\r\n" STANDARD_HEADERS);
mg_send_head(c, 200, strlen(json_str), "Content-Type: application/json\r\n" STANDARD_HEADERS);
mg_printf(c, "%s", json_str);
free(json_str);
}