Page 1 of 1

How to catch an asynchronous HTTP not responding

Posted: Friday 04 September 2020 16:46
by Number8
Hello,
In case a web server does not respond to an asynchronous HTTP request, as expected there is a timeout and dzVents logs in red full details of the calling url (including sensitive information). Is there a way to catch the timeout before it is logged by dzVents runtime?
Thank you

Running dzVents 3.0.9

Re: How to catch an asynchronous HTTP not responding

Posted: Friday 04 September 2020 17:33
by waaren
Number8 wrote: Friday 04 September 2020 16:46 In case a web server does not respond to an asynchronous HTTP request, as expected there is a timeout and dzVents logs in red full details of the calling url (including sensitive information). Is there a way to catch the timeout before it is logged by dzVents runtime?
If you mean the error message like 2020-09-04 17:31:00.559 Error: Error opening url: http: //somedomain/someAPI?param=1
then the message you see is not generated by dzVents but in core domoticz. Messages from dzVents will show the text "dzVents" somewhere in the logline.

Re: How to catch an asynchronous HTTP not responding

Posted: Friday 04 September 2020 18:52
by Number8
Yes I mean this message, no way to catch it?

Re: How to catch an asynchronous HTTP not responding

Posted: Friday 04 September 2020 20:28
by waaren
Number8 wrote: Friday 04 September 2020 18:52 Yes I mean this message, no way to catch it?
You will have to modify the domoticz source code and compile locally to achieve that.

A workaround could be to check the url (ping or another tool) before sending the real thing.

Re: How to catch an asynchronous HTTP not responding

Posted: Saturday 05 September 2020 9:45
by Number8
At first place I had the idea to use ping. But it does not answer the case where the network is up and the service is down. I might give a shot to modify the module that send the error message. Any direction to search for?

Re: How to catch an asynchronous HTTP not responding

Posted: Saturday 05 September 2020 14:46
by waaren
Number8 wrote: Saturday 05 September 2020 9:45 At first place I had the idea to use ping. But it does not answer the case where the network is up and the service is down. I might give a shot to modify the module that send the error message. Any direction to search for?
In latest Beta

Code: Select all

main/SQLHelper.cpp:3516:           _log.Log(LOG_ERR, "Error opening url: %s", itt->_sValue.c_str());

Re: How to catch an asynchronous HTTP not responding

Posted: Saturday 05 September 2020 21:08
by zicht
Hi

No need to modify files.

In Lua and DZ :
You could use curl, but be aware it could freeze domoticz for a couple of seconds.
WIth curl you can set max time to open and max time to wait for the request to finisch.
If you set both at max 9 seconds you will never see the error.

See curl documentation depending on you platform, this can be done on linux AND windows systems
windows example :
"start /b /realtime curl.exe --connect-timeout 5 --max-time 9"
Works fine for me on most http requests. The Start /b / realtime is just to get highest priority on windows curl.

Also you need to implement a check on valid data, you could endup with a empty response or a partial response.
Imagination is the limit. good luck with your approach.

Re: How to catch an asynchronous HTTP not responding

Posted: Sunday 06 September 2020 10:14
by kiddigital
Number8 wrote:Yes I mean this message, no way to catch it?
Do you have a few example loglines showing what you are trying to catch?

Most Domoticz hardware devices that talk to some API over http do this in a synchronous way. Errors like time-outs or other failures have to be handled within the implementation code of the devices themselves.

Re: How to catch an asynchronous HTTP not responding

Posted: Sunday 06 September 2020 10:45
by waaren
kiddigital wrote: Sunday 06 September 2020 10:14 Most Domoticz hardware devices that talk to some API over http do this in a synchronous way. Errors like time-outs or other failures have to be handled within the implementation code of the devices themselves.
This question is about the (async) openURL call in dzVents

Re: How to catch an asynchronous HTTP not responding

Posted: Sunday 06 September 2020 10:50
by kiddigital
waaren wrote:...
This question is about the (async) openURL call in dzVents
Ah.. ok Image