-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Even in the face of urllib.error.HTTPError, return the json
Previously, if we caught a urllib.error.HTTPError, we would try to parse the json response. If we succeeded we would return _only_ the `message` field of that response. If we failed, we're return the text of the response. By "return" here, I actually mean "pack up into an Exception object and throw it". Now, if succeed in parsing the response as json, we extend that exception object so that it also contains the JSON that we got. That way, client code can find extra goodies in the json["data"] field. Also added a utility to the examples so they can be easily run against a locally running `algod`.
- Loading branch information
Showing
4 changed files
with
44 additions
and
3 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
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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from algosdk import error, transaction | ||
|
||
from utils import get_algod_client, algod_env | ||
|
||
algod = get_algod_client(*algod_env()) | ||
|
||
# This program is "#pragma version 5, +". It will fail because no arguments are on the stack. | ||
lsig = transaction.LogicSigAccount(b"\x05\x08") | ||
sender = lsig.address() | ||
# Get suggested parameters | ||
params = algod.suggested_params() | ||
|
||
amount = 10000 | ||
txn = transaction.PaymentTxn(sender, params, sender, amount) | ||
lstx = transaction.LogicSigTransaction(txn, lsig) | ||
try: | ||
txid = algod.send_transaction(lstx) | ||
print("Impossible! Exception will have been thrown") | ||
except error.AlgodHTTPError as e: | ||
print(e.data) |
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