Skip to content

Commit

Permalink
Handle problem retrieving file but we still have it locally
Browse files Browse the repository at this point in the history
  • Loading branch information
ariselseng committed Aug 19, 2020
1 parent 1105cb2 commit 0e32175
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/NorwegianBanks.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Ariselseng\NorwegianBanks;

use Desarrolla2\Cache\File as FileCache;
use GuzzleHttp\Exception\BadResponseException;

class NorwegianBanks
{
Expand Down Expand Up @@ -35,10 +36,18 @@ private function downloadData()
} else {
return;
}
try {
$response = (new \GuzzleHttp\Client())->get(self::XlsFileUrl, [
'headers' => $headers,
]);
} catch (BadResponseException $e) {
// handle file exists but there is an error at the server.
if ($xlsFileExists) {
return;
}
throw $e;
}

$response = (new \GuzzleHttp\Client())->get(self::XlsFileUrl, [
'headers' => $headers,
]);

if ($response->getStatusCode() === 200 && $response->getBody()->getSize() > 0) {
file_put_contents($this->xlsFilePath, $response->getBody()->getContents(), LOCK_EX);
Expand Down

0 comments on commit 0e32175

Please # to comment.