jublo / codebird-js

A Twitter library in JavaScript.
https://www.jublo.net/projects/codebird/js
GNU General Public License v3.0
384 stars 97 forks source link

exception when no internet connection exist #105

Closed fadaytak closed 8 years ago

fadaytak commented 9 years ago

hi,

im using this library with titanium and works fine, but when im testing it without internet connection to make some alert for client saying that a something was happen and we cannot share actually ....

but the problem i can't catch any thing no error ...

is the library get back error to call function ? some exemple to do this ?

var result = {};
var params = {
        screen_name: userName
    };
    try{
        codebird.__call("users_show", params, function(reply) {
                if(reply){
                    result = reply;
                }                   
                callback(result);
            }, false // this parameter required
        );
    }catch(e){
        Ti.API.error("Twitter >> getUserData | " + e.message);
        callback(result);
    }

cordially

hamzaezzi commented 9 years ago

you can add in codebird.js file this code

    // function called when an error occurs, including a timeout
    xml.onerror = function(e) {
        callback(null,null,e);
    };
    xml.timeout = 30000;  // in milliseconds

and when you call __call function you do like this

codebird.__call("users_show", params, function(reply,rate,err) {
            if(err){
                  alert("err" + JSON.stringify(err));
            }
            if(reply){
                result = reply;
            }                   
            callback(result);
        }, false // this parameter required
    );

you can use this file

https://github.com/hamzaezzi/codebird-js/blob/develop/codebird.js

hope help you

fadaytak commented 9 years ago

yes !!! thanks, works fine

mynetx commented 9 years ago

Reopening this issue as this should be part of Codebird itself. @hamzaezzi Can you send a PR, please?

hamzaezzi commented 9 years ago

done

mynetx commented 9 years ago

@hamzaezzi Please test in develop branch now.