jasonkneen / RESTe

A simple JavaScript REST / API helper for Titanium

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HTTPClient onError and responseText

botmaster opened this issue · comments

Hello,
I dont understand the error handler :

http.onerror = function(e) {
            e.url = args.url;

            function retry() {
                log("Retrying");
                makeHttpRequest(args, onLoad, onError);
            }

            if (onError) {
                // if we have an onError method, use it
                onError(parseJSON(http.responseText), retry);

                // if the local error returns, we get here
                config.onError && config.onError(parseJSON(http.responseText), retry);

            } else if (config.onError) {
                // otherwise fallback to the one specified in config
                config.onError(parseJSON(http.responseText), retry);
            } else if (onLoad) {
                // otherwise revert to the onLoad callback
                onLoad(parseJSON(http.responseText), retry);
            } else {
                // and if reste's not specified, error!
                throw "RESTe :: No error handler / callback for: " + args.url;
            }
        }

According the doc, Ti.Network.createHTTPClient().responseText is set to null if an error was received or no data was returned.
In this case http.responseTextalways return null or ""
Maybe it should be e.responseText ?

are you experiencing an issue / error with RESTe? What docs are you referring to -- the readme?

I refere to the Appcelerator doc :
http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Network.HTTPClient-property-responseText

responseText : StringREADONLY
Response as text.
Set to null if an error was received or no data was returned.

In the http.onerror callback (reste.js), I understand that responseText is always set to null. So why do that parseJSON(http.responseText) ?
But my english is bad and I probably do not understand the documentation.

Please try the module -- if you have tried it and it's not working correctly, please raise an issue but AFAIK it's working correctly.