Skip to content

Commit

Permalink
Rate limiting (#2)
Browse files Browse the repository at this point in the history
* Rate limiting

* Make stan happy

* Throw original exception if cannot be json decoded

* Remove unnecessary count check on errors

* Clean up code

---------

Co-authored-by: Morgan Arnel <[email protected]>
  • Loading branch information
williamrenfrew and morganarnel authored Sep 12, 2023
1 parent 5d3b7d8 commit ee08ff6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Services/SalesforceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Exception;
use Omniphx\Forrest\Providers\Laravel\Facades\Forrest;
use Omniphx\Forrest\Providers\Laravel\LaravelCache;
use SynergiTech\Salesforce\Exceptions\AuthenticationFailedException;

class SalesforceService
Expand All @@ -14,8 +15,13 @@ public static function table(string $tableName): TableService
return new TableService($tableName);
}

protected static function authenticate(): void
protected static function authenticate(bool $force = false): void
{
/** @var LaravelCache $cache */
$cache = app(LaravelCache::class);
if (!$force && $cache->has('token')) {
return;
}
try {
Forrest::authenticate();
} catch (Exception $ex) {
Expand Down
4 changes: 4 additions & 0 deletions src/Services/TableService.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ protected function decodeError(SalesforceException $ex): stdClass
throw new JsonParseErrorException('Error message received was not valid json. Message: ' . $message);
}

if (!$errors) {
throw $ex;
}

/** @var stdClass{errorCode:string, message:string} $error */
return $errors[0];
}
Expand Down

0 comments on commit ee08ff6

Please sign in to comment.