Possible errors in docs around request sendasync

On this page:

https://electricimp.com/docs/api/httprequest/sendasync/

The sample code says that the sendasync callback functions as response object:

server.log("Code: " + response.statuscode + ". Message: " + response.message);

However, when I use this code, it says that there is no message in response. Either the sample code is wrong or needs to be updated or I’m doing something wrong.

On a related note, can the response page be expanded to exactly what fields are available? Or are there 2 response objects, one for the callback and one for the response to a http request? In that case, please consider changing the sample code to use something other than response to make it less confusing.

http://electricimp.com/docs/api/httpresponse/

Thanks.

Yep, @dig090, that’s a bug, and it’s fixed now.

There are two objects. In the case of the httprequest.sendasnyc() callback function, what’s returned is a Squirrel table with the following keys: statuscode, header and body.

This table is not an httpresponse object, which doesn’t have any code-accessible fields other than a header, which has to be set using the httpresponse.header() method.

Because of the confusion that has arisen (understandably) between these two objects, I’ve altered the name of variable passed to the callback in the example code.

Once again, thanks for the spot, @dig090.

Thanks @smittytone, looks a lot better. You could change the function name to be processResult as opposed to response. :slight_smile: