Skip to content

Commit e5cb4fe

Browse files
Merge pull request #12 from CodaProtocol/fix/error-handling
[Fix] Error Handling New Block Subscription
2 parents 51ea074 + 37cb44a commit e5cb4fe

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

CodaClient.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ def _graphql_request(self, query: str, variables: dict = {}):
7676
}
7777
self.logger.debug("Sending a Query: {}".format(payload))
7878
response = requests.post(self.endpoint, json=payload, headers=headers)
79-
if response.status_code == 200:
79+
resp_json = response.json()
80+
if response.status_code == 200 and "errors" not in resp_json:
8081
self.logger.debug("Got a Response: {}".format(response.json()))
81-
return response.json()
82+
return resp_json
8283
else:
8384
print(response.text)
8485
raise Exception(
@@ -97,6 +98,7 @@ async def _graphql_subscription(self, query: str, variables: dict = {}, callback
9798
self.logger.info("Listening to GraphQL Subscription...")
9899

99100
uri = self.websocket_endpoint
101+
self.logger.info(uri)
100102
async with websockets.client.connect(uri, ping_timeout=None) as websocket:
101103
# Set up Websocket Connection
102104
self.logger.debug("WEBSOCKET -- Sending Hello Message: {}".format(hello_message))
@@ -464,15 +466,15 @@ async def listen_block_confirmations(self, callback):
464466
'''
465467
await self._graphql_subscription(query, {}, callback)
466468

467-
async def listen_new_blocks(self, pk: str, callback):
468-
"""Creates a subscription for new blocks created by a proposer using a particular private key.
469+
async def listen_new_blocks(self, callback):
470+
"""Creates a subscription for new blocks, calls `callback` each time the subscription fires.
469471
470472
Arguments:
471-
pk {PublicKey} -- The public key to use to filter blocks
473+
callback(block) {coroutine} -- This coroutine is executed with the new block as an argument each time the subscription fires
472474
"""
473475
query = '''
474-
subscription($pk:PublicKey){
475-
newBlock(publicKey:$pk){
476+
subscription(){
477+
newBlock(){
476478
creator
477479
stateHash
478480
protocolState {

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setup(
1414
name='CodaClient',
15-
version='0.0.13',
15+
version='0.0.14',
1616
python_requires='>=3.5',
1717
description='A Python wrapper around the Coda Daemon GraphQL API.',
1818
github='http://github.com/CodaProtocol/coda-python',

0 commit comments

Comments
 (0)