Skip to content

Commit

Permalink
Better error reporting in exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
zulucrypto committed Aug 12, 2018
1 parent 0082a84 commit 3064ab8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Horizon/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public function __construct($baseUrl, $networkPassphrase)
$this->baseUrl = $baseUrl;
$this->httpClient = new Client([
'base_uri' => $baseUrl,
'exceptions' => false,
]);
$this->networkPassphrase = $networkPassphrase;
}
Expand Down Expand Up @@ -185,7 +186,7 @@ public function get($relativeUrl)
$decoded = null;
if ($e->getResponse()) {
$decoded = Json::mustDecode($e->getResponse()->getBody());
throw HorizonException::fromRawResponse($relativeUrl, 'GET', $decoded);
throw HorizonException::fromRawResponse($relativeUrl, 'GET', $decoded, $e);
}
// No response, something else went wrong
else {
Expand Down
2 changes: 1 addition & 1 deletion src/Horizon/Exception/HorizonException.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static function fromRawResponse($requestedUrl, $httpMethod, $raw, ClientE
*/
public function __construct($title, Throwable $previous = null)
{
parent::__construct($title, 0, 1, __FILE__, __LINE__, $previous);
parent::__construct($title, 0, 1, $previous->getFile(), $previous->getLine(), $previous);
}

/**
Expand Down
20 changes: 19 additions & 1 deletion src/Transaction/TransactionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,13 +518,31 @@ protected function generateSequenceNumber()
{
$this->ensureApiClient();

$account = $this->apiClient
->getAccount($this->accountId->getAccountIdString());

if (!$account) {
throw new \ErrorException(sprintf('Account not found: %s', $this->accountId->getAccountIdString()));
}

try {
return $this->apiClient
->getAccount($this->accountId->getAccountIdString())
->getSequence() + 1
;
} catch (HorizonException $e) {
throw new \ErrorException(sprintf('Could not get sequence number for %s, does this account exist?', $this->accountId->getAccountIdString()));
$e->getTraceAsString();

print "**************\n" . $e->getTraceAsString() . "\n****************\n";

throw new \ErrorException(
sprintf('Could not get sequence number for %s, does this account exist?', $this->accountId->getAccountIdString()),
$e->getCode(),
$e->getSeverity(),
__FILE__,
__LINE__,
$e
);
}
}

Expand Down

0 comments on commit 3064ab8

Please sign in to comment.