Nanoleaf: Check for connection error before accessing status/body. Closes #4390
This commit is contained in:
parent
43bd3774e8
commit
8b9f128881
2 changed files with 26 additions and 11 deletions
|
|
@ -34,8 +34,11 @@ long APIRequest(std::string method, std::string location, std::string URI, json*
|
|||
{
|
||||
httplib::Result result = client.Get(URI.c_str());
|
||||
|
||||
status = result->status;
|
||||
body = result->body;
|
||||
if(httplib::Error::Success == result.error())
|
||||
{
|
||||
status = result->status;
|
||||
body = result->body;
|
||||
}
|
||||
}
|
||||
else if(method == "PUT")
|
||||
{
|
||||
|
|
@ -43,30 +46,42 @@ long APIRequest(std::string method, std::string location, std::string URI, json*
|
|||
{
|
||||
httplib::Result result = client.Put(URI.c_str(), request_data->dump(), "application/json");
|
||||
|
||||
status = result->status;
|
||||
body = result->body;
|
||||
if(httplib::Error::Success == result.error())
|
||||
{
|
||||
status = result->status;
|
||||
body = result->body;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
httplib::Result result = client.Put(URI.c_str());
|
||||
|
||||
status = result->status;
|
||||
body = result->body;
|
||||
if(httplib::Error::Success == result.error())
|
||||
{
|
||||
status = result->status;
|
||||
body = result->body;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(method == "DELETE")
|
||||
{
|
||||
httplib::Result result = client.Delete(URI.c_str());
|
||||
|
||||
status = result->status;
|
||||
body = result->body;
|
||||
if(httplib::Error::Success == result.error())
|
||||
{
|
||||
status = result->status;
|
||||
body = result->body;
|
||||
}
|
||||
}
|
||||
else if(method == "POST")
|
||||
{
|
||||
httplib::Result result = client.Post(URI.c_str());
|
||||
|
||||
status = result->status;
|
||||
body = result->body;
|
||||
if(httplib::Error::Success == result.error())
|
||||
{
|
||||
status = result->status;
|
||||
body = result->body;
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------*\
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ void DetectNanoleafControllers()
|
|||
}
|
||||
catch(...)
|
||||
{
|
||||
LOG_DEBUG("[Nanoleaf] Could not connect to device at %s:%s using auth_token %s", device["ip"].get<std::string>().c_str(), device["port"].get<std::string>().c_str(), device["auth_token"].get<std::string>().c_str());
|
||||
LOG_DEBUG("[Nanoleaf] Could not connect to device at %s:%d using auth_token %s", device["ip"].get<std::string>().c_str(), device["port"].get<int>(), device["auth_token"].get<std::string>().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue