Changeset 5246133 for protocols/twitter


Ignore:
Timestamp:
2012-11-09T00:23:44Z (12 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
5d749ad
Parents:
fb351ce
Message:

Updated error response parsing. Also, use this for 401 responses so for example
the auth errors caused by NTP desync are clearer:

<root> twitter - Login error: Authentication failure (401 Unauthorized

(Timestamp out of bounds))

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter_lib.c

    rfb351ce r5246133  
    169169{
    170170        static char *ret = NULL;
    171         struct xt_node *root, *node, *err;
     171        json_value *root, *err;
    172172
    173173        g_free(ret);
    174174        ret = NULL;
    175175
    176         /* EX:
    177         {"errors":[{"message":"Rate limit exceeded","code":88}]} */
    178176        if (req->body_size > 0) {
    179                 root = xt_from_string(req->reply_body, req->body_size);
    180                
    181                 for (node = root; node; node = node->next)
    182                         if ((err = xt_find_node(node->children, "error")) && err->text_len > 0) {
    183                                 ret = g_strdup_printf("%s (%s)", req->status_string, err->text);
    184                                 break;
    185                         }
    186 
    187                 xt_free_node(root);
     177                root = json_parse(req->reply_body);
     178                err = json_o_get(root, "errors");
     179                if (err->type == json_array && (err = err->u.array.values[0]) &&
     180                    err->type == json_object) {
     181                        const char *msg = json_o_str(err, "message");
     182                        if (msg)
     183                                ret = g_strdup_printf("%s (%s)", req->status_string, msg);
     184                }
     185                json_value_free(root);
    188186        }
    189187
     
    216214                   throwing 401s so I'll keep treating this one as fatal
    217215                   only during login. */
    218                 imcb_error(ic, "Authentication failure");
     216                imcb_error(ic, "Authentication failure (%s)",
     217                               twitter_parse_error(req));
    219218                imc_logout(ic, FALSE);
    220219                return NULL;
Note: See TracChangeset for help on using the changeset viewer.