HTTP Request - handle failures

62 views
Skip to first unread message

fraczw...@gmail.com

unread,
Jun 1, 2017, 3:11:15 PM6/1/17
to Automate
Now, when I use the HTTP Request block and it fails (because for example there is no internet connection at the moment), the fiber stops and there is nothing I can do about it.

If HTTP Request block had an alternative red failure path, I could retry the request after a specific delay or something like that.

I have a simple flow that cheks one URL periodically and when there is a connectoin problem, I have to restart the flow manually because it stops.

meke...@gmail.com

unread,
Jun 1, 2017, 3:38:57 PM6/1/17
to Automate
Prior to the HTTP request, use a Network Connected? block with immediate option. If no network is connected, use another Network Connected? block that's set to when changed. You can then have this block & the previous immediate check then flow to a ping block to ensure there's definitely a connection.

You'll also do well to use the failure catch block before your HTTP request, with the fail block going to a delay block before flowing back to the HTTP request block.

fraczw...@gmail.com

unread,
Jun 1, 2017, 3:51:56 PM6/1/17
to Automate, meke...@gmail.com
The HTTP Request may fail because of the server is down, too, so the Network Connected block does not solve the issue.

I have not found the Catch block (I was looking for Try). However, it does not seem to work with the HTTP Request block. I placed it directly before the HTTP Request, set the retry count to 5 and the fiber still stops immediately with a "Unknown host" error in log when I turn off the wifi.


CATCH FAILURE
(OK)     (FAIL) ---- DELAY (OK) -|
|                                |
HTTP <-------------------------- |

meke...@gmail.com

unread,
Jun 1, 2017, 3:55:44 PM6/1/17
to Automate
The Network Connected? block isn't a complete solution, but it will make your flow more robust because it will eliminate delay looping when there isn't a valid internet connection. The Failure Catch block should work for when the server is down.

meke...@gmail.com

unread,
Jun 1, 2017, 4:05:52 PM6/1/17
to Automate
The Failure Catch works for me as per the log:


2017-06-01 21:00:26.583 INFO 1936@3: HTTP request
2017-06-01 21:00:26.600 FAIL 1936@3: java.net.UnknownHostException: Unable to resolve host "www.google.co.uk": No address associated with hostname
2017-06-01 21:00:26.611 INFO 1936@5: Delay
2017-06-01 21:00:36.628 INFO 1936@3: HTTP request
2017-06-01 21:00:37.929 INFO 1936@4: Toast show
2017-06-01 21:00:37.959 INFO 1936@0: Stopped at end

The failure makes the flow delay for 10 seconds and retries. When I enable a data connection, the request is successful and then continues to the toast show message (showing the status code 200).

fraczw...@gmail.com

unread,
Jun 1, 2017, 4:58:36 PM6/1/17
to Automate, meke...@gmail.com
Yeah, it works. I put the catch on the wrong fiber and there was an earlier HTTP request that made me think the catch does not work.

Thank you!
Reply all
Reply to author
Forward
0 new messages