I am using the Casablanca REST SDK to make a webservice. The webservice has the client pass JSON through the URL and processes it. However in some cases if I send JSON that contains an array, it will crash the service. The strange part is the handler method that actually handles the JSON runs all the way through and ends before the error is given. My main function is:
int main()
{
std::string ip;
std::string port;
std::ifstream inputStream;
inputStream.open("ip_port.config");
while(!inputStream.eof())
{
inputStream >> ip;
inputStream >> port;
}
inputStream.close();
std::string uri = "http://"+ip+":"+port+"/";
//set up URL
web::http::uri u(U(uri));
//set up listener for URL
web::http::experimental::listener::http_listener listener(u);
listener.support(methods::GET, handle_get);
try
{
pplx::task<void> l = listener.open();
while(true)
{
l.wait();
sleep(1);
}
listener.close().wait();
}
catch(int e)
{
std::stringstream errorMessage;
errorMessage << "Error: " << e;
logRequest(errorMessage.str(), "Error Message");
}
return 0;
}
I have put two prints: "Beginning of Handler" and "End of Handler" in the handle_get function, which are both printed, leading me to beleive that the cause of the error has something to do with the while loop with the listener, but the error it gives has nothing to do with the listener:
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::substr
Im trying to wrap my head around what about the listener could return that error.