Skip to content

Commit

Permalink
Lib: Introduce maxErrorRetryAttempts
Browse files Browse the repository at this point in the history
  • Loading branch information
tflanagan committed Jan 15, 2016
1 parent fcd3e9c commit 139336f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions quickbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ class QuickBase {
'errcode' => 0,
'errtext' => 'No error',
'errdetail' => ''
)
),

'maxErrorRetryAttempts' => 3
);

public function __construct($options = array()){
Expand Down Expand Up @@ -102,6 +104,8 @@ class QuickBaseQuery {
public $options = array();
public $response = array();

private $nErrors = 0;

protected $payload = '';

public function __construct(&$parent, $action = '', $options = array()){
Expand Down Expand Up @@ -174,7 +178,9 @@ final public function constructPayload(){

final public function checkForAndHandleError(){
if($this->response['errcode'] != $this->settings['status']['errcode']){
if($this->response['errcode'] == 4 && isset($this->parent->settings['username']) && isset($this->parent->settings['password'])){
++$this->nErrors;

if($this->nErrors <= $this->parent->settings['maxErrorRetryAttempts'] && $this->response['errcode'] == 4 && isset($this->parent->settings['username']) && isset($this->parent->settings['password'])){
try {
$newTicket = $this->parent->api('API_Authenticate', array(
'username' => $this->parent->settings['username'],
Expand Down Expand Up @@ -258,6 +264,12 @@ final public function transmit(){
curl_close($ch);

if($response === false){
++$this->nErrors;

if($this->nErrors <= $this->settings['maxErrorRetryAttempts']){
return $this->transmit();
}

throw new QuickBaseError($errno, $error);
}

Expand Down

0 comments on commit 139336f

Please sign in to comment.