Skip to content

Commit ee08ff6

Browse files
Rate limiting (#2)
* 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 <morgan@synergitech.co.uk>
1 parent 5d3b7d8 commit ee08ff6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Services/SalesforceService.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Exception;
66
use Omniphx\Forrest\Providers\Laravel\Facades\Forrest;
7+
use Omniphx\Forrest\Providers\Laravel\LaravelCache;
78
use SynergiTech\Salesforce\Exceptions\AuthenticationFailedException;
89

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

17-
protected static function authenticate(): void
18+
protected static function authenticate(bool $force = false): void
1819
{
20+
/** @var LaravelCache $cache */
21+
$cache = app(LaravelCache::class);
22+
if (!$force && $cache->has('token')) {
23+
return;
24+
}
1925
try {
2026
Forrest::authenticate();
2127
} catch (Exception $ex) {

src/Services/TableService.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ protected function decodeError(SalesforceException $ex): stdClass
213213
throw new JsonParseErrorException('Error message received was not valid json. Message: ' . $message);
214214
}
215215

216+
if (!$errors) {
217+
throw $ex;
218+
}
219+
216220
/** @var stdClass{errorCode:string, message:string} $error */
217221
return $errors[0];
218222
}

0 commit comments

Comments
 (0)