Skip to content

Commit e6901f5

Browse files
committed
Adds proper reaction to symfony.sh outage
1 parent e34a594 commit e6901f5

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/Service/OfficialEndpointProxy.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
namespace App\Service;
1313

14+
use App\Exception\OfficialEndpointNotAvailableExtension;
1415
use GuzzleHttp\Psr7\Request;
1516
use Http\Client\Exception\NetworkException;
1617
use Http\Client\HttpClient;
1718
use Symfony\Component\Cache\Simple\FilesystemCache;
19+
use Symfony\Component\HttpFoundation\Response;
1820

1921
/**
2022
* Class OfficialEndpointProxy
@@ -106,6 +108,13 @@ private function getDecodedResponse(Request $request)
106108
$response = $this->client->sendRequest($request);
107109
$decodedResponse = json_decode($response->getBody(), true);
108110

111+
if(!in_array($response->getStatusCode(), range(200, 299))) {
112+
if ($this->cacheEndpoint && $this->cache->has($this->getCacheId($request))) {
113+
return $this->cache->get($this->getCacheId($request));
114+
}
115+
return [];
116+
}
117+
109118
if (json_last_error() !== JSON_ERROR_NONE) {
110119
$decodedResponse = $response->getBody();
111120
}
@@ -116,10 +125,8 @@ private function getDecodedResponse(Request $request)
116125

117126
return $decodedResponse;
118127
} catch (NetworkException $e) {
119-
if ($this->cacheEndpoint) {
120-
if ($this->cache->has($this->getCacheId($request))) {
121-
return $this->cache->get($this->getCacheId($request));
122-
}
128+
if ($this->cacheEndpoint && $this->cache->has($this->getCacheId($request))) {
129+
return $this->cache->get($this->getCacheId($request));
123130
}
124131
throw $e;
125132
}

src/Service/Provider/PackagesProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private function getLocalRecipe(array $package)
132132
});
133133
}
134134
if (count($localRecipes) > 0) {
135-
return $localRecipes[0];
135+
return reset($localRecipes);
136136
}
137137
return null;
138138
}

0 commit comments

Comments
 (0)