Changeset a7b9ec7 for protocols/twitter


Ignore:
Timestamp:
2010-05-23T13:49:54Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
186bd04
Parents:
bb5ce4d1
Message:

Improved error reporting (get textual HTTP error message and error message
from Twitter API response if possible).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter_lib.c

    rbb5ce4d1 ra7b9ec7  
    117117}
    118118
     119/* Warning: May return a malloc()ed value, which will be free()d on the next
     120   call. Only for short-term use. */
     121static char *twitter_parse_error(struct http_request *req)
     122{
     123        static char *ret = NULL;
     124        struct xt_parser *xp;
     125        struct xt_node *node;
     126        char *err_s = NULL;
     127       
     128        g_free(ret);
     129        ret = NULL;
     130       
     131        xp = xt_new(NULL, NULL);
     132        xt_feed(xp, req->reply_body, req->body_size);
     133       
     134        if ((node = xt_find_node(xp->root, "hash")) &&
     135            (node = xt_find_node(node->children, "error")) &&
     136            node->text_len > 0)
     137                err_s = node->text;
     138       
     139        if (err_s)
     140        {
     141                ret = g_strdup_printf("%s (%s)", req->status_string, err_s);
     142                xt_free(xp);
     143                return ret;
     144        }
     145        else
     146        {
     147                return req->status_string;
     148        }
     149}
     150
    119151static void twitter_http_get_friends_ids(struct http_request *req);
    120152
     
    124156void twitter_get_friends_ids(struct im_connection *ic, int next_cursor)
    125157{
    126         struct twitter_data *td = ic->proto_data;
    127 
    128158        // Primitive, but hey! It works...     
    129159        char* args[2];
     
    196226                // It didn't go well, output the error and return.
    197227                if (++td->http_fails >= 5)
    198                         imcb_error(ic, "Could not retrieve friends. HTTP STATUS: %d", req->status_code);
     228                        imcb_error(ic, "Could not retrieve friends: %s", twitter_parse_error(req));
    199229               
    200230                return;
     
    526556                // It didn't go well, output the error and return.
    527557                if (++td->http_fails >= 5)
    528                         imcb_error(ic, "Could not retrieve " TWITTER_HOME_TIMELINE_URL ". HTTP STATUS: %d", req->status_code);
     558                        imcb_error(ic, "Could not retrieve " TWITTER_HOME_TIMELINE_URL ": %s", twitter_parse_error(req));
    529559               
    530560                return;
     
    578608                // It didn't go well, output the error and return.
    579609                if (++td->http_fails >= 5)
    580                         imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL " HTTP STATUS: %d", req->status_code);
     610                        imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL ": %s", twitter_parse_error(req));
    581611               
    582612                return;
     
    617647void twitter_get_statuses_friends(struct im_connection *ic, int next_cursor)
    618648{
    619         struct twitter_data *td = ic->proto_data;
    620 
    621649        char* args[2];
    622650        args[0] = "cursor";
     
    642670        if (req->status_code != 200) {
    643671                // It didn't go well, output the error and return.
    644                 imcb_error(ic, "Could not post message... HTTP STATUS: %d", req->status_code);
     672                imcb_error(ic, "Could not post message: %s", twitter_parse_error(req));
    645673                return;
    646674        }
     
    652680void twitter_post_status(struct im_connection *ic, char* msg)
    653681{
    654         struct twitter_data *td = ic->proto_data;
    655 
    656682        char* args[2];
    657683        args[0] = "status";
     
    667693void twitter_direct_messages_new(struct im_connection *ic, char *who, char *msg)
    668694{
    669         struct twitter_data *td = ic->proto_data;
    670 
    671695        char* args[4];
    672696        args[0] = "screen_name";
Note: See TracChangeset for help on using the changeset viewer.