Skip to content
Snippets Groups Projects
Commit 47fd9107 authored by Eirik Morland's avatar Eirik Morland
Browse files

Issue #3398173 by eiriksm: Make sure the result is an array if using newer http libraries

parent 6cbc7c13
No related branches found
No related tags found
1 merge request!7Try more variants to return an array
......@@ -4,6 +4,7 @@ namespace Drupal\sparkpost;
use Drupal\Core\Config\ConfigFactory;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Stream;
use SparkPost\SparkPost;
/**
......@@ -78,12 +79,18 @@ class ClientService implements ClientServiceInterface {
/**
* {@inheritdoc}
*/
public function sendMessage(array $message) {
public function sendMessage(array $message) : ?array {
$client = $this->getClient();
try {
$promise = $client->transmissions->post($message);
$response = $promise->wait();
return $response->getBody();
$data = $response->getBody();
if ($data instanceof Stream) {
// Let's treat it as a HTTP response, and try to parse the body into
// JSON.
$data = json_decode($data->getContents(), TRUE);
}
return $data;
}
catch (\Exception $e) {
\Drupal::logger('sparkpost')->error($e->getMessage());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment