-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Kristian Feldsam <feldsam@gmail.com>
- Loading branch information
Showing
6 changed files
with
25 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
use FioApi\Exceptions\TooGreedyException; | ||
use GuzzleHttp\Client; | ||
use GuzzleHttp\ClientInterface; | ||
use GuzzleHttp\Exception\BadResponseException; | ||
use GuzzleHttp\Exception\GuzzleException; | ||
use GuzzleHttp\RequestOptions; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
|
@@ -59,27 +61,35 @@ public function setLastId(string $id): void | |
|
||
try { | ||
$client->request('get', $url); | ||
} catch (\GuzzleHttp\Exception\BadResponseException $e) { | ||
} catch (BadResponseException $e) { | ||
$this->handleException($e); | ||
} | ||
} | ||
|
||
/** | ||
* @param string $url | ||
* @return TransactionList | ||
* @throws GuzzleException | ||
*/ | ||
private function downloadTransactionsList(string $url): TransactionList | ||
Check failure on line 74 in src/FioApi/Downloader.php GitHub Actions / PHP 7.4 on ubuntu-latest --prefer-lowest
Check failure on line 74 in src/FioApi/Downloader.php GitHub Actions / PHP 8.0 on ubuntu-latest --prefer-lowest
Check failure on line 74 in src/FioApi/Downloader.php GitHub Actions / PHP 8.1 on ubuntu-latest --prefer-lowest
|
||
{ | ||
$client = $this->getClient(); | ||
/** @var ?ResponseInterface $response */ | ||
$response = null; | ||
$transactions = null; | ||
|
||
try { | ||
/** @var ?ResponseInterface $response */ | ||
$response = $client->request('get', $url); | ||
} catch (\GuzzleHttp\Exception\BadResponseException $e) { | ||
if ($response) { | ||
$transactions = json_decode($response->getBody()->getContents())->accountStatement; | ||
} | ||
} catch (BadResponseException $e) { | ||
$this->handleException($e); | ||
} | ||
|
||
return TransactionList::create(json_decode($response->getBody()->getContents())->accountStatement); | ||
return TransactionList::create($transactions); | ||
} | ||
|
||
private function handleException(\GuzzleHttp\Exception\BadResponseException $e): void | ||
private function handleException(BadResponseException $e): void | ||
{ | ||
if ($e->getCode() == 409) { | ||
throw new TooGreedyException('You can use one token for API call every 30 seconds', $e->getCode(), $e); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters