Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6d673c
commit e9a4a67
Showing
1 changed file
with
52 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,57 @@ | ||
Exceptions | ||
========== | ||
|
||
Exceptions for this library are designed so the developer can watch at a general level, or for something very specific. | ||
All exceptions extend from [RippledException](../src/Exception/RippledException.php), which extends from PHP's base | ||
Exception. | ||
|
||
The more specific extensions extend from [RippledException](../src/Exception/RippledException.php). | ||
If you're not interested in exactly what exception is being thrown, add a single catch for `RippledException`. | ||
|
||
- [RippledException](../src/Exception/RippledException.php) | ||
- [InvalidParameterException](../src/Exception/RippledException.php) | ||
- [TransactionException](../src/Exception/TransactionException.php) | ||
- [TransactionSignException](../src/Exception/TransactionSignException.php) | ||
- [TransactionTypeException](../src/Exception/TransactionTypeException.php) | ||
On the other hand, there are several other exceptions so you may elegantly handle them separately. | ||
|
||
## API Example | ||
|
||
The most likely exceptions you may be interested in catching and forwarding the message for are the | ||
`InvalidParameterException` and the `ResponseErrorException` as these may be due to invalid user input. | ||
|
||
Other exceptions thrown are most likely an indication of a developer error, or an issue communicating with the remote | ||
rippled server. | ||
|
||
In this example, the 2 exceptions above are caught, with a catch-all of `RippledException` which covers everything else. | ||
|
||
```php | ||
<?php | ||
|
||
use FOXRP\Rippled\Client; | ||
use FOXRP\Rippled\Exception\InvalidParameterException; | ||
use FOXRP\Rippled\Exception\ResponseErrorException; | ||
use FOXRP\Rippled\Exception\RippledException; | ||
|
||
$client = new Client('https://s1.ripple.com:51234'); | ||
|
||
$balance = null; | ||
|
||
try { | ||
$response = $client->send('account_info', [ | ||
'account' => 'rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn' | ||
]); | ||
|
||
// Set balance if successful. | ||
if ($response->isSuccess()) { | ||
$data = $response->getResult(); | ||
$balance = $data['account_data']['Balance']; | ||
} | ||
|
||
} catch (InvalidParameterException $e) { | ||
// Catch validation errors that occur before the request is sent. | ||
// i.e. missing required params, unrecognized params, etc. | ||
$error = $e->getMessage(); | ||
} catch (ResponseErrorException $e) { | ||
// Catch errors sent back from the API. | ||
$error = $e->getMessage(); | ||
} catch (RippledException $e) { | ||
// Catch all other exceptions which may be thrown by the library. | ||
$error = $e->getMessage(); | ||
} | ||
``` | ||
|
||
You can find a list of all exceptions in [src/Exception](../src/Exception/RippledException.php). |