Skip to content

Commit a255944

Browse files
committed
Moved around some code for improved error detection
1 parent 6df8985 commit a255944

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/SendGrid/Api.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,13 @@ public function retrieve ($action, array $params) {
108108
$this->debug("Querying URL: $url");
109109
curl_setopt($this->ch, CURLOPT_URL, $url);
110110
$data = curl_exec($this->ch);
111+
$decoded = json_decode($data);
111112

112-
if (empty($data)) {
113-
throw new RuntimeException("No data received from server. No Internet connection?");
113+
if (empty($decoded)) {
114+
$error_code = json_last_error();
115+
throw new RuntimeException("Error retrieving data. No Internet connection? [$error_code]");
114116
}
115117

116-
$decoded = json_decode($data);
117118
if (isset($decoded->error)) {
118119
$code = $decoded->error->code;
119120
$msg = $decoded->error->message;
@@ -125,7 +126,7 @@ public function retrieve ($action, array $params) {
125126
throw new LogicException($msg . " [Code: $code]");
126127
}
127128

128-
return json_decode($data);
129+
return $decoded;
129130
}
130131

131132
/**

0 commit comments

Comments
 (0)