"Trying to access array offset"
Closed this issue · 4 comments
Hi, I have been trying to send an email out on Kartra using Postmark Servers but I keep getting this error, the email send to another list with around 2k people but this one is failing to send. The email is going to around 12k people. I am presented with the following message:
"Unfortunately, the sendout has failed to go through and your gateway returned the following error message: "Postmark general exception: Trying to access array offset on value of type null in /var/www/kartra/1614264772/libraries_not_ci/vendor/wildbit/postmark-php/src/Postmark/PostmarkClientBase.php at line 168".
IMPORTANT: This is NOT a Kartra-generated error. Therefore, we recommend you to contact your gateway's support team to find out what this error means, and how to solve it."
Any ideas what the cause of this might be?
Cheers
Matt
Hey Matt, could you reach out to support@postmarkapp.com and we'll look into this? Thanks!
@MatthewArnott thanks for bringing up this issue! This exception has been generated in the error handling logic used when sending requests to our API. Based on the code path in the error message, some requests you have been making failed, I'm guessing with a 422 Unprocessable Entity or another non-standard response code.
A more descriptive and useful error message should have been returned instead of that generic exception. I believe this may have been caused by some backwards incompatible changes present in more recent versions of PHP (7.4+) that our error handling code may not fully support yet. We will look into fixing these error messages in a future release.
Closed due to age. If this persists - please let us know.
This is still a problem. The code assumes that the $body is a valid array with an 'ErrorCode' key. Apparently this is not always the case.
On line 181 of PostmarkClientBase.php we see $ex->setPostmarkApiErrorCode($body['ErrorCode']);
.
There should be a check on $body['ErrorCode']
, something like $body['ErrorCode'] ?? ''
where the empty string could be a default message.
The same goes for line 182 with $ex->message = $body['Message'];
. There is no guarantee that the Message
key exists in $body
.