From 139336f398cbf34675d3752fb41cb4b523d7b92b Mon Sep 17 00:00:00 2001 From: Tristian Flanagan Date: Fri, 15 Jan 2016 16:15:22 -0500 Subject: [PATCH] Lib: Introduce maxErrorRetryAttempts --- quickbase.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/quickbase.php b/quickbase.php index ea55f39..8a761d3 100644 --- a/quickbase.php +++ b/quickbase.php @@ -41,7 +41,9 @@ class QuickBase { 'errcode' => 0, 'errtext' => 'No error', 'errdetail' => '' - ) + ), + + 'maxErrorRetryAttempts' => 3 ); public function __construct($options = array()){ @@ -102,6 +104,8 @@ class QuickBaseQuery { public $options = array(); public $response = array(); + private $nErrors = 0; + protected $payload = ''; public function __construct(&$parent, $action = '', $options = array()){ @@ -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'], @@ -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); }