Dealing with [url]WWW.error[/url]

Hi!

I am using WWW to send tweets (to Twitter, obviously). While it works when everything goes well, I cannot manage to deal with WWW error properly when an error happens (i.e. wrong username or no connection). I’m using the well known TwitterSend function. The error is always null, even when I know for sure that, for example, the password is wrong.

The following function always prints “Twitter posting done!” even if there is a known error during posting:

function TwitterSend(username: String, password: String, message: String) { 
    var twitterURL: String = "http://" + username + ":" + password + "@twitter.com/statuses/update.json"; 
    var twitterForm : WWWForm = new WWWForm(); 
    twitterForm.AddField("status", message); 
    
    var WWWpost : WWW = new WWW(twitterURL, twitterForm); 
    print("Tweeting...");
    
    yield WWWpost;
        
    print("Done...");
    if (WWWpost.error != null) { 
        print ( "Twitter posting error...");
    } else { 
        print ( "Twitter posting done!"); 
    } 
}

Am I doing something wrong?

Are you sure Twitter handles login errors by generating an HTTP error? Try looking at the data string returned by the operation - it may be that some kinds of error with Twitter deliver the message that way instead.

Um… If you write the address directly in a browser, with wrong data, you get “{“errors”:[{“code”:32,“message”:“Could not authenticate you”}]}”

I think I already tried printing WWW error. I’ll do that again and report back asap. Thanks!

That isn’t an HTTP error, so I would expect it is defined somewhere in the Twitter API docs. There isn’t really any way for WWW.error to respond to that kind of thing, unfortunately, so you’ll have to detect the error in the response yourself.

Thank you, andeee. I guess I’ll use WWW.data and look for the ‘error’ substring. That should work.