Skip to content

Commit

Permalink
catch exceptions inside startHTTPSServer and startHTTPServer
Browse files Browse the repository at this point in the history
also print the cause of the exception to simplify debugging

Change-Id: Ib1125056abfff77de978da53027e26e689861d69
  • Loading branch information
rdementi committed Jun 19, 2024
1 parent 7a98558 commit 7be1b3b
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/pcm-sensor-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3181,23 +3181,35 @@ void my_get_callback( HTTPServer* hs, HTTPRequest const & req, HTTPResponse & re

int startHTTPServer( unsigned short port ) {
HTTPServer server( "", port );
// HEAD is GET without body, we will remove the body in execute()
server.registerCallback( HTTPRequestMethod::GET, my_get_callback );
server.registerCallback( HTTPRequestMethod::HEAD, my_get_callback );
server.run();
try {
// HEAD is GET without body, we will remove the body in execute()
server.registerCallback( HTTPRequestMethod::GET, my_get_callback );
server.registerCallback( HTTPRequestMethod::HEAD, my_get_callback );
server.run();
} catch (std::exception & e)
{
std::cerr << "Exception caught: " << e.what() << "\n";
return -1;
}
return 0;
}

#if defined (USE_SSL)
int startHTTPSServer( unsigned short port, std::string const & cFile, std::string const & pkFile) {
HTTPSServer server( "", port );
server.setPrivateKeyFile ( pkFile );
server.setCertificateFile( cFile );
server.initialiseSSL();
// HEAD is GET without body, we will remove the body in execute()
server.registerCallback( HTTPRequestMethod::GET, my_get_callback );
server.registerCallback( HTTPRequestMethod::HEAD, my_get_callback );
server.run();
try {
server.setPrivateKeyFile ( pkFile );
server.setCertificateFile( cFile );
server.initialiseSSL();
// HEAD is GET without body, we will remove the body in execute()
server.registerCallback( HTTPRequestMethod::GET, my_get_callback );
server.registerCallback( HTTPRequestMethod::HEAD, my_get_callback );
server.run();
} catch (std::exception & e)
{
std::cerr << "Exception caught: " << e.what() << "\n";
return -1;
}
return 0;
}
#endif
Expand Down

0 comments on commit 7be1b3b

Please sign in to comment.