Skip to content

Commit

Permalink
Merge pull request #17 from resslinger/patch-1
Browse files Browse the repository at this point in the history
add error handling for short write error
  • Loading branch information
repat authored Jan 20, 2022
2 parents 3e7a5d7 + 76a7d63 commit 43ce455
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/PlentymarketsRestClient/PlentymarketsRestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class PlentymarketsRestClient
const WAIT_ERROR_SHORT_PERIOD_READ_LIMIT = 5;
const ERROR_SHORT_PERIOD_READ_LIMIT = 'short period read limit reached';

const WAIT_ERROR_SHORT_PERIOD_WRITE_LIMIT = 10;
const ERROR_SHORT_PERIOD_WRITE_LIMIT = 'short period write limit reached';

const THROTTLING_PREFIX_LONG_PERIOD = 'X-Plenty-Global-Long-Period';
const THROTTLING_PREFIX_SHORT_PERIOD = 'X-Plenty-Global-Short-Period';
const THROTTLING_PREFIX_ROUTE = 'X-Plenty-Route';
Expand Down Expand Up @@ -90,10 +93,13 @@ public function singleCall($method, $path, $params = [])
} catch (\Exception $e) {

// For a better Plentymarkets exception handling. Sometimes the limit is not correct
// TODO possible handle recursion errors
if (stripos($e->getMessage(), self::ERROR_SHORT_PERIOD_READ_LIMIT) !== false) {
sleep(self::WAIT_ERROR_SHORT_PERIOD_READ_LIMIT);
$this->singleCall($method, $path, $params);
// TODO possible handle recursion errors
} elseif (stripos($e->getMessage(), self::ERROR_SHORT_PERIOD_WRITE_LIMIT) !== false) {
sleep(self::WAIT_ERROR_SHORT_PERIOD_WRITE_LIMIT);
$this->singleCall($method, $path, $params);
}

if ($this->handleExceptions === true) {
Expand Down

0 comments on commit 43ce455

Please sign in to comment.