Skip to content
This repository has been archived by the owner on Sep 28, 2020. It is now read-only.

Commit

Permalink
So turns out using getBody()->getContents is a bad idea as get conten…
Browse files Browse the repository at this point in the history
…ts can end up returning null
  • Loading branch information
Chris-Pratt-Clystnet committed Jun 15, 2018
1 parent c612def commit e4b000f
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/Vtiger.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,8 @@ protected function login($sessionData)
]
]);

/** @var ResponseInterface $unprocessedResponse */
$unprocessedResponse = $response;
// decode the response
$loginResult = json_decode($response->getBody()->getContents());
$loginResult = json_decode($response->getBody());
$tryCounter++;
} while (!isset($loginResult->success) && $tryCounter <= $this->maxRetries);

Expand All @@ -151,7 +149,7 @@ protected function login($sessionData)
}

// If api login failed
if ($unprocessedResponse->getStatusCode() !== 200 || !$loginResult->success) {
if ($response->getStatusCode() !== 200 || !$loginResult->success) {
if (!$loginResult->success) {
if ($loginResult->error->code == "INVALID_USER_CREDENTIALS" || $loginResult->error->code == "INVALID_SESSIONID") {
if ($this->sessionDriver == 'file') {
Expand All @@ -162,10 +160,10 @@ protected function login($sessionData)
Redis::del('clystnet_vtiger');
}
} else {
$this->_processResult($unprocessedResponse);
$this->_processResult($response);
}
} else {
$this->_checkResponseStatusCode($unprocessedResponse);
$this->_checkResponseStatusCode($response);
}
} else {
// login ok so get sessionid and update our session
Expand Down Expand Up @@ -237,17 +235,15 @@ protected function getToken()
]
]);

$unprocessedResponse = $response;
$processedResponse = json_decode($response->getBody()->getContents());
$tryCounter++;
} while (!isset($processedResponse->success) && $tryCounter <= $this->maxRetries);
} while (!isset(json_decode($response->getBody())->success) && $tryCounter <= $this->maxRetries);

if ($tryCounter >= $this->maxRetries) {
throw new VtigerError("Could not complete get token request within ".$this->maxRetries." tries", 6);
}

// decode the response
$challenge = $this->_processResult($unprocessedResponse);
$challenge = $this->_processResult($response);

// Everything ok so create a token from response
$output = array(
Expand Down Expand Up @@ -497,7 +493,7 @@ protected function _processResult($response)
$this->_checkResponseStatusCode($response);

// decode the response
$data = json_decode($response->getBody()->getContents());
$data = json_decode($response->getBody());

if (!isset($data->success)) {
throw new VtigerError("Success property not set on VTiger response", 2);
Expand Down

0 comments on commit e4b000f

Please sign in to comment.