PHP Fatal Error when api call fails
-
When I try to edit a post, I get a fatal error, and the page fails to reload.
The error occurs when this plugin tries to call the cloudflare api, “WORDPRESS ERROR : sslread() return error -9806”. I’m not worried about that error, instead I think the error handling in this plugin can be improved.
Here’s what I see in debug.log:
PHP Fatal error: Cannot use object of type WP_Error as array in wp-content/plugins/cloudflare-cache-purge/lib/ccpurge.class.php on line 95And the relevant code, with some comments added from me:
function make_api_request($api_method, $extra_post_variables = null){ //REMOVED FOR READABILITY if( is_wp_error( $results ) ){ ccpurge_transaction_logging(print_r($results->get_error_message(), true), 'Wordpress Error'); //seems like we want a return statement here, or better detection in the next if statement when the $results object doesn't have a 'response' key } if($results['response']['code'] != '200'){ ccpurge_transaction_logging(print_r($results, true), 'error'); } return json_decode($results['body']); }
https://www.ads-software.com/plugins/cloudflare-cache-purge/
- The topic ‘PHP Fatal Error when api call fails’ is closed to new replies.