- Issue created by @swirt
- 🇮🇳India Shreya_98
The error occurs in the code at line 136 of the PostApiQueueBase.php file, where we are using method_exists() with an incorrect argument type i.e. $response_code = (method_exists($response, 'getStatusCode')) ? $response->getStatusCode() : 500;
In this line, we trying to check if the $response object has a method called getStatusCode(). However, the $response variable seems to hold an HTTP response instance, which should already have the getStatusCode() method. Therefore, there's no need to use method_exists() here.
As per my knowledge i think To solve this issue, we can directly call the getStatusCode() method on the $response object.
no need to using method_exists(). - 🇮🇳India dineshkumarbollu
Hi
In this line$response_code = (method_exists($response, 'getStatusCode')) ? $response->getStatusCode() : 500;
if No response then they are adding $response_code as '500' i.e Internal Server Error, the issue is Response they are getting at line 135 is not a object$response = $this->processItem($item->data);
. - 🇮🇳India mohd sahzad
i have created patch for this call to method exists throws an error.
- Status changed to Needs review
over 1 year ago 10:23am 23 August 2023 - Status changed to Needs work
over 1 year ago 1:41am 24 August 2023 - 🇺🇸United States swirt Florida
Wow. I have never seen such a fast response from so many people. Thanks for all the help.
Patch #2 is targeting the wrong problem. We can't forgo the call to method_exists because sometimes the response is not an object. So, as @dineshkumarbollu called out removing it does not prevent the problem we would have calling ->getStatusCode() on something that is not a response object.I think the defensive check of ` if (!is_int($response)) {` in patch #4 is close, but affirming the indirect thing, instead of affirming the direct thing. What we really want to check is, is the $response we are about to act on an actual \Psr\Http\Message\ResponseInterface So it would be more direct to have the check be
if ($response instanceof ResponseInterface) {
- 🇺🇸United States swirt Florida
The simplest fix is to replace
$response_code = (method_exists($response, 'getStatusCode')) ? $response->getStatusCode() : 500; $reason_phrase = (method_exists($response, 'getReasonPhrase')) ? $response->getReasonPhrase() : 'none provided';
with
$response_code = ($response instanceof ResponseInterface) ? $response->getStatusCode() : 500; $reason_phrase = ($response instanceof ResponseInterface) ? $response->getReasonPhrase() : 'none provided';
- Status changed to Fixed
over 1 year ago 1:57am 24 August 2023 Automatically closed - issue fixed for 2 weeks with no activity.