Title: Fatal error in Endpoint_Api::save_cache() method
Last modified: January 14, 2022

---

# Fatal error in Endpoint_Api::save_cache() method

 *  Resolved [Zlatev](https://wordpress.org/support/users/entr/)
 * (@entr)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/fatal-error-in-endpoint_apisave_cache-method/)
 * Hi there,
 * We are experiencing fatal errors for unauthorized requests to WooCommerce endpoints.
   We tracked the issue down to the `Endpoint_Api::save_cache()` method.
 *     ```
       public function save_cache( $result, \WP_REST_Server $server, \WP_REST_Request $request ) {
   
       		if ( ! empty( $result ) && is_array( $result ) && isset( $result['data']['status'] ) && 200 !== (int) $result['data']['status'] ) {
       			return $result;
       		}
       ...
       }
       ```
   
 * Turns out `$result['data']` is not guaranteed to be an Array and this will result
   in a fatal error:
 *     ```
       PHP Fatal error:  Uncaught Error: Cannot use object of type stdClass as array in .../wp-content/plugins/wp-rest-cache/includes/api/class-endpoint-api.php:232
       ```
   
 * It might be due to the fact WC is returning `WP_Error` objects in their permission
   handlers but this should be further investigated.
 * However, to more reliably retrieve the actual HTTP status code of the ongoing
   response you should use the `http_response_code()` php function. By the time `
   rest_pre_serve_request` filter is run that header is already set by `WP_REST_Server::
   serve_request()` method.
 * Let us know if you need more information on the matter.
    -  This topic was modified 4 years, 4 months ago by [Zlatev](https://wordpress.org/support/users/entr/).

Viewing 1 replies (of 1 total)

 *  Plugin Author [Richard Korthuis](https://wordpress.org/support/users/rockfire/)
 * (@rockfire)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/fatal-error-in-endpoint_apisave_cache-method/#post-15821594)
 * Hi [@entr](https://wordpress.org/support/users/entr/)
 * Sorry for the extremely late reply!
 * We just released a new version of our plugin which should solve this issue.

Viewing 1 replies (of 1 total)

The topic ‘Fatal error in Endpoint_Api::save_cache() method’ is closed to new replies.

 * ![](https://ps.w.org/wp-rest-cache/assets/icon-256x256.png?rev=3328849)
 * [WP REST Cache](https://wordpress.org/plugins/wp-rest-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-rest-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-rest-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-rest-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-rest-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-rest-cache/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Richard Korthuis](https://wordpress.org/support/users/rockfire/)
 * Last activity: [3 years, 11 months ago](https://wordpress.org/support/topic/fatal-error-in-endpoint_apisave_cache-method/#post-15821594)
 * Status: resolved