Support » Plugin: Postmark for WordPress » CRITICAL Uncaught Error: Cannot use object of type WP_Error as array

  • Resolved nelsonamaya

    (@nelsonamaya)


    Hi, today I’m checking the WooCommerce fatal errors log and found this error several times:

    CRITICAL Uncaught Error: Cannot use object of type WP_Error as array in wp-content/plugins/postmark-approved-wordpress-plugin/wp-mail.php:241

    I can see you have had some incidents today (https://status.postmarkapp.com/incidents) and they seem to be related to this error.

    After checking the code involved in the error, I see you are not validating the API response after this line (218):

    $response = wp_remote_post( 'https://api.postmarkapp.com/email', $args );

    So in the line 241 it’s throwing the critical error mentioned above as $response is not an array but a WP_Error:

    'response' => sanitize_text_field( $response['body'] )

    It caused some additional issues in our WooCommerce site, as it affected the checkout ajax response and some customers didn’t get to the Thank You page.

    Could you help us by adding this validation? Do you think you can release a new version with this fix as soon as possible?

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Patrick Graham

    (@prileygraham)

    Hi @nelsonamaya,

    Sorry to hear about the incident today causing issues for your checkout process and happy to help!

    I just released v1.11.4 of the plugin that I believe addresses this issue by validating that the response is an array before attempting to insert the result into the logs table. It also now checks for a WP_Error and logs the error message instead of the API response in that scenario.

    You can view the changes made to that code here:

    https://github.com/wildbit/postmark-wordpress/blob/master/wp-mail.php#L236-L251

    Let me know if you see any issues with the fix and thanks for reporting this!

    nelsonamaya

    (@nelsonamaya)

    Hi @prileygraham,

    Thank you so much for your prompt reply and for releasing this new version. I think this change does the trick.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.