Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handling of connection failures in client #37

Open
DrLex0 opened this issue Jan 5, 2017 · 1 comment
Open

Better handling of connection failures in client #37

DrLex0 opened this issue Jan 5, 2017 · 1 comment

Comments

@DrLex0
Copy link

DrLex0 commented Jan 5, 2017

There is no way to explicitly catch connection failures in client code. The implementation in client/client.cc intercepts exceptions during connect, by means of its ‘ExceptionPrinter’. This prints the exception on std::cout and leaves the PromiseHttp::Response in a limbo state, meaning the calling program cannot know what exactly went wrong. It can only rely on a default error state and a timeout.

For instance, if I run the http_client.cc example with a resource path starting with a local IP address that is serving nothing (e.g. http://127.0.0.1:4321). It will print: “Got exception: Could not connect: Resource temporarily unavailable” and then wait for the 5-second barrier timeout even though it is obvious that the request has already failed.
I have tried modifying the example by defining other handlers than Async::IgnoreException, but it makes no difference. I cannot manage to trigger a lambda that takes an exception_ptr, it is never invoked.

@timlyo
Copy link

timlyo commented Nov 8, 2019

It seems that Pistache can now run a lambda in response to connection errors:

response.then([&](Http::Response response) {
                      std::cout << "Successful";
                  },
                  [](std::exception_ptr e) {
                      try {
                          std::rethrow_exception(e);
                      } catch (const Pistache::Error &e) {
                          std::cerr << e.what();
                      }
                  })

I haven't tried cancelling the timeout from this though so I'm not sure if that works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants