Skip to content

Commit 139336f

Browse files
committed
Lib: Introduce maxErrorRetryAttempts
1 parent fcd3e9c commit 139336f

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

quickbase.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ class QuickBase {
4141
'errcode' => 0,
4242
'errtext' => 'No error',
4343
'errdetail' => ''
44-
)
44+
),
45+
46+
'maxErrorRetryAttempts' => 3
4547
);
4648

4749
public function __construct($options = array()){
@@ -102,6 +104,8 @@ class QuickBaseQuery {
102104
public $options = array();
103105
public $response = array();
104106

107+
private $nErrors = 0;
108+
105109
protected $payload = '';
106110

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

175179
final public function checkForAndHandleError(){
176180
if($this->response['errcode'] != $this->settings['status']['errcode']){
177-
if($this->response['errcode'] == 4 && isset($this->parent->settings['username']) && isset($this->parent->settings['password'])){
181+
++$this->nErrors;
182+
183+
if($this->nErrors <= $this->parent->settings['maxErrorRetryAttempts'] && $this->response['errcode'] == 4 && isset($this->parent->settings['username']) && isset($this->parent->settings['password'])){
178184
try {
179185
$newTicket = $this->parent->api('API_Authenticate', array(
180186
'username' => $this->parent->settings['username'],
@@ -258,6 +264,12 @@ final public function transmit(){
258264
curl_close($ch);
259265

260266
if($response === false){
267+
++$this->nErrors;
268+
269+
if($this->nErrors <= $this->settings['maxErrorRetryAttempts']){
270+
return $this->transmit();
271+
}
272+
261273
throw new QuickBaseError($errno, $error);
262274
}
263275

0 commit comments

Comments
 (0)