Closed dmatora closed 8 months ago
Same problem. Is there any plan to fix it?
I also have this problem. When API response with non-200 HTTP code and some JSON with error code - that variable contains string instead of an object and ->getBody() call fails.
@mnovozhylov anything new here? would it be easy with PR?
Hi @bodva Feel free to create a PR, I'll re-view once I have a chance.
I've notice that this happens when you change permissions for your key and then the access token become invalidate.
This happens in this file: vendor/upwork/php-upwork-oauth2/src/Upwork/API/AuthTypes/OAuth2ClientLib.php:103
try {
// do not use getParsedResponse, it returns an array
// but we need a raw json that will be decoded and returned as StdClass object
$response = $this->getInstance()->getResponse($request);
} catch (\GuzzleHttp\Exception\ClientException $e) {
$eResponse = $e->getResponse();
$response = $eResponse->getBody()->getContents();
} catch (\Exception $e) {
$response = $e->getResponseBody();
}
ApiDebug::p('got response from server', $response);
return (string) $response->getBody();
It seems the reason is the $response variable in the last line is not always Response object. For example, $eResponse->getBody()->getContents() returns string.
I can't create PR so I created a patch: issue-13-call-getbody-string.patch
Hi @madlobz Thank you for your contribution! Fixed in v2.4.2.
When server returns 403, API crashes with following exception