Nodemcu-firmware: HTTP.get no callback on error

Created on 20 Jun 2017  路  7Comments  路  Source: nodemcu/nodemcu-firmware

http.get on a local IP that is not available (not assigned) fails but does not call callback

Expected behavior

The callback should be called allways, even on all failures

in the example it should print
callback

Actual behavior

The callback is not called

-- > http.get("http://192.1.1.254/",nil,function() print "callback" end)
-- > HTTP client: Disconnected with error: -11
-- HTTP client: Connection timeout
-- HTTP client: Connection timeout

Test code

-- http.get("http://192.1.1.254/",nil,function() print "callback" end)

NodeMCU version

NodeMCU custom build by frightanic.com
branch: master
commit: c8ac5cfb912ff206b03dd7c60ffbb2dafb83fe5e
SSL: true
modules: bit,file,gpio,http,i2c,net,node,ow,pwm,rtctime,sjson,sntp,tmr,uart,wifi,tls
build built on: 2017-06-17 17:53
powered by Lua 5.1.4 on SDK 2.1.0(116b762)

Hardware

Standard ESP6288 E-12 Dev Board

bug

All 7 comments

I have same behavior with http.post()
Module author @vowstar

I'd argue the current behavior is correct. The callback parameter is specified/documented as

The callback function to be invoked when the response has been received; it is invoked with the arguments status_code, body and headers

In your case no connection can be established and thus no status code, no body and no headers.

yes but the doc also says

Each request method takes a callback which is invoked when the response has been received from the server. The first argument is the status code, which is either a regular HTTP status code, or -1 to denote a DNS, connection or out-of-memory failure, or a timeout (currently at 10 seconds).

Interesting, never noted that paragraph. It makes sense and we should ensure consistency in the docs.

It would also be useful (at least) to know when processing of an http call is finished, so I can issue the next call.

Yes, you are right. When timeout it need a callback with error code -1.

PR merged -> closing

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ildar picture ildar  路  5Comments

ShAzmoodeh picture ShAzmoodeh  路  6Comments

Michal78S picture Michal78S  路  6Comments

vsky279 picture vsky279  路  7Comments

dicer picture dicer  路  6Comments