client timeout

Jan 26, 2015 at 6:38 PM
I am not exactly clear on the behaviour of the client timeout. I know there is one, and that it defaults to 30 seconds.

What exactly happens? does it throw an exception? Does it return some status code I should be trying to capture? I can't seem to sort it out from the debugger what is happening? does it just fake out that it is returning an empty response and I should check for this? Is ther an example of code that is handling the timeout?

I do have a large try catch around the send request task and an exception is currently being thrown, however my sent task also includes a nested task that extracts the json and I am unclear where my exception is actually coming from, as it should be from a timeout as I currently have no working server.

Thanks for your time,
Jan 27, 2015 at 12:21 AM
Hi Robyn,

The http_client timeout value is used as a general timeout related to an individual HTTP request. I.e. if the request doesn't get any response or data within the timeout value then the request is canceled and treated as having timed out. A time out is different than an HTTP status code. All network errors, like timeouts, are exposed as exceptions in the library.

If a network error, like a timeout, occurs before the HTTP headers have completely arrived an http_exception is thrown out of the task returned from http_client::request(...). If the error occurs after the HTTP headers have completely arrived then an exception is thrown from the task returned by any of the following methods: http_response::extract_string(), http_response::extract_vector(), http_response::extract_json, or http_response::content_ready(). For more information about programming with tasks I recommend you take a look at the following resource.

For an example with a timeout you can take a look at the test cases. Specifically the request_timeout test case try to connect to a server that never responds to the request. It is hard for me to understand the code you have from your written description, it would be much better if you directly posted the code.