Open krazkidd opened 4 months ago
Here's an example try-catch block:
try
{
api.Login(dlgLogin.GetEmail(), dlgLogin.GetPassword());
wxCommandEvent* evt = new wxCommandEvent(EVT_LOGIN);
evt->SetEventObject(this);
evt->SetString("Login succeeded!");
QueueEvent(evt);
}
catch (oatpp::web::client::RequestExecutor::RequestExecutionError &e)
{
std::cerr << e.getErrorCode() << std::endl;
std::cerr << e.getReadErrorCode() << std::endl;
std::cerr << e.getMessage() << std::endl;
wxCommandEvent* evt = new wxCommandEvent(EVT_API_ERROR);
evt->SetEventObject(this);
evt->SetString("Unknown network error!");
QueueEvent(evt);
}
catch (std::exception &e)
{
wxCommandEvent* evt = new wxCommandEvent(EVT_API_ERROR);
evt->SetEventObject(this);
evt->SetString("Login failed!");
QueueEvent(evt);
}
We need to be able to detect connection issues and other network problems and report them to the user. As of now, we can detect errors coming from the API itself (see kdeck::Api::HandleResponse) but all API requests are invoked from various parts of the UI code so there's not a universal handler of other kinds of errors and we just show a generic message.
In #49, it was discovered that a particular exception type is thrown if a server cannot be authenticated (see RequestExecutor::RequestExecutionError. It is not known yet if this is the only exception type that can come from Oat++'s client framework.