summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Carver2019-01-24 19:03:48 (GMT)
committerMark Carver2019-01-24 19:03:48 (GMT)
commita72c7ee1684e379dfe7b67af868495cc11d4e060 (patch)
tree279eb3fc2d714af671b3b54b34ad51efdceb208f
parentfacb313201ae612fa39bbad2254f4a71c2cd6f82 (diff)
Issue #3027569 by markcarver, just_like_good_vibes: Error: Unsupported operand types during providers JSON discovery
-rw-r--r--src/Plugin/Provider/ProviderBase.php19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/Plugin/Provider/ProviderBase.php b/src/Plugin/Provider/ProviderBase.php
index 10ddeb3..565b18b 100644
--- a/src/Plugin/Provider/ProviderBase.php
+++ b/src/Plugin/Provider/ProviderBase.php
@@ -171,17 +171,19 @@ class ProviderBase extends PluginBase implements ProviderInterface {
* The URI to retrieve JSON from.
* @param array $options
* The options to pass to the HTTP client.
+ * @param \Exception|null $exception
+ * The exception thrown if there was an error, passed by reference.
*
- * @return array|null
- * The requested JSON array or NULL if an error occurred.
+ * @return array
+ * The requested JSON array.
*/
- protected function requestJson($uri, array $options = []) {
- $json = NULL;
+ protected function requestJson($uri, array $options = [], &$exception = NULL) {
+ $json = [];
$options += [
'method' => 'GET',
'headers' => [
- 'User-Agent' => 'Drupal Bootstrap (https://www.drupal.org/project/bootstrap)',
+ 'User-Agent' => 'Drupal Bootstrap 8.x-3.x (https://www.drupal.org/project/bootstrap)',
],
];
@@ -192,15 +194,16 @@ class ProviderBase extends PluginBase implements ProviderInterface {
$response = $client->send($request, $options);
if ($response->getStatusCode() == 200) {
$contents = $response->getBody(TRUE)->getContents();
- $json = Json::decode($contents);
+ $json = Json::decode($contents) ?: [];
}
}
catch (GuzzleException $e) {
- // Intentionally left blank.
+ $exception = $e;
}
catch (\Exception $e) {
- // Intentionally left blank.
+ $exception = $e;
}
+
return $json;
}