Skip to content

Commit

Permalink
Better catching of exceptions
Browse files Browse the repository at this point in the history
See #5
  • Loading branch information
joedolson committed Aug 16, 2023
1 parent f7d4f5c commit 0b14ef7
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/wp-to-twitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,18 +451,23 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false
'rate-24-reset' => $headers['x-app-limit-24hour-reset'],
);
update_option( 'wpt_app_limit', $rate_limit );
} catch ( Exception $e ) {
} catch ( \GuzzleHttp\Exception\RequestException $e ) {
// Get Guzzle exception response.
$response = $e->getResponse();
$headers = $response->getHeaders();
$rate_limit = array(
'rate-limit' => $headers['x-rate-limit-remaining'],
'rate-reset' => $headers['x-rate-limit-reset'],
'rate-24' => $headers['x-app-limit-24hour-limit'],
'rate-24-reset' => $headers['x-app-limit-24hour-reset'],
);
update_option( 'wpt_app_limit', $rate_limit );
$http_code = $response->getStatusCode();
if ( method_exists( $e, 'getResponse' ) ) {
$response = $e->getResponse();
$headers = $response->getHeaders();
$rate_limit = array(
'rate-limit' => $headers['x-rate-limit-remaining'],
'rate-reset' => $headers['x-rate-limit-reset'],
'rate-24' => $headers['x-app-limit-24hour-limit'],
'rate-24-reset' => $headers['x-app-limit-24hour-reset'],
);
update_option( 'wpt_app_limit', $rate_limit );
$http_code = $response->getStatusCode();
}
} catch ( Exception $e ) {
$http_code = 400;
$notice = __( 'Unhandled response', 'wp-to-twitter' );
}
$notice = '';
} else {
Expand Down

0 comments on commit 0b14ef7

Please sign in to comment.