WordPress.org

Plugin Directory

Changeset 525736


Ignore:
Timestamp:
04/01/12 02:28:17 (2 years ago)
Author:
dllh
Message:

Show more useful error output when we have a 403 error. I think Posterous always sends back a retry-after header of 1 second (the error content they send back suggests waiting "a second" between requests), but it'd be helpful to know if people ever get any other value.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • posterous-importer/branches/v2api/posterous.php

    r525735 r525736  
    1010*/ 
    1111 
    12 // TODO: Actually honor the retry-after headers instead of using an arbitrary wait time. 
     12// TODO: Actually honor the retry-after headers instead of using an arbitrary wait time. This probably requires doing some fun cron stuff. 
    1313// TODO: Figure out Posterous's weird shortcode/hashing thing for inserting images into pages and body_html (e.g. [[posterous-content:jhsmtHnEjaoooaxfmmbm]]) 
    1414// Do something with private posts. 
     
    232232     */ 
    233233    function handle_bad_response( $data, $code ) { 
    234         printf( "<em>%s</em><br />\n", __( 'Got HTTP code' ) . ' ' . $code . ' ' . __( 'from' ) . ' ' . $url ); 
     234        switch ( $code ) { 
     235            case 403: 
     236                printf( "<p><strong>Error: </strong>%s</p>\n", __( 'Got HTTP code' ) . ' ' . $code ); 
     237                printf( "<p><strong>Retry After (seconds): </strong>%s</p>", $data['headers']['retry-after'] ); 
     238                printf( "<p><strong>Rate Limit: </strong>%s</p>", $data['headers']['x-ratelimit-limit'] ); 
     239                printf( "<p><strong>Rate Limit Remaining: </strong>%s</p>", $data['headers']['x-ratelimit-remaining'] ); 
     240                break; 
     241            default: 
     242                printf( "<strong>Error: </strong>%s<br />\n", __( 'Got HTTP code' ) . ' ' . $code );     
     243        }        
    235244        exit(); 
    236245    } 
Note: See TracChangeset for help on using the changeset viewer.