Skip to content

Commit 3865229

Browse files
committed
Update TellerClient.php
try
1 parent cd8674b commit 3865229

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/TellerClient.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ public function accountsCount(): int
4141

4242
public function getAccountDetails($accountId)
4343
{
44-
return $this->get("/accounts/{$accountId}/details");
44+
$response = $this->request('GET', "/accounts/{$accountId}/details");
45+
$data = $this->parseJsonResponse($response);
46+
return $data;
4547
}
4648

4749
public function getAccountBalances($accountId)
@@ -198,4 +200,22 @@ private function request($method, $path, $data = null): bool|string
198200
}
199201
}
200202

203+
public function parseJsonResponse($response)
204+
{
205+
// Check if the response is empty or not a string
206+
if (empty($response) || !is_string($response)) {
207+
throw new Exception("Invalid or empty response");
208+
}
209+
210+
// Attempt to decode the JSON response
211+
$data = json_decode($response, false, 512, JSON_THROW_ON_ERROR);
212+
213+
// Check for JSON decoding errors
214+
if (json_last_error() !== JSON_ERROR_NONE) {
215+
throw new Exception("JSON Error: " . json_last_error_msg());
216+
}
217+
218+
return $data;
219+
}
220+
201221
}

0 commit comments

Comments
 (0)