[exceptions] Add base exceptions package (#6)

* [exceptions] Remove unused import

* [exceptions] Add base exceptions package & move InvalidRPCReplyError to base exceptions package
pull/7/head
Janet Liang 5 years ago committed by GitHub
parent fdfe7f255f
commit 6881847544
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      pyhmy/account.py
  2. 4
      pyhmy/blockchain.py
  3. 14
      pyhmy/exceptions.py
  4. 10
      pyhmy/rpc/exceptions.py

@ -4,11 +4,14 @@ from .rpc.request import (
from .rpc.exceptions import ( from .rpc.exceptions import (
RPCError, RPCError,
InvalidRPCReplyError,
RequestsError, RequestsError,
RequestsTimeoutError RequestsTimeoutError
) )
from .exceptions import (
InvalidRPCReplyError
)
from .blockchain import ( from .blockchain import (
get_sharding_structure get_sharding_structure
) )

@ -2,8 +2,8 @@ from .rpc.request import (
rpc_request rpc_request
) )
from .rpc.exceptions import ( from .exceptions import (
InvalidRPCReplyError, InvalidRPCReplyError
) )
_default_endpoint = 'http://localhost:9500' _default_endpoint = 'http://localhost:9500'

@ -0,0 +1,14 @@
from .rpc.exceptions import (
RPCError,
RequestsError,
RequestsTimeoutError
)
class InvalidRPCReplyError(RuntimeError):
"""
Exception raised when RPC call returns unexpected result
Generally indicates Harmony API has been updated & pyhmy library needs to be updated as well
"""
def __init__(self, method, endpoint):
super().__init__(f'Unexpected reply for {method} from {endpoint}')

@ -1,4 +1,3 @@
import json
import requests import requests
@ -10,15 +9,6 @@ class RPCError(RuntimeError):
def __init__(self, method, endpoint, error): def __init__(self, method, endpoint, error):
super().__init__(f'Error in reply from {endpoint}: {method} returned {error}') super().__init__(f'Error in reply from {endpoint}: {method} returned {error}')
class InvalidRPCReplyError(RuntimeError):
"""
Exception raised when RPC call returns unexpected result
Generally indicates Harmony API has been updated & pyhmy library needs to be updated as well
"""
def __init__(self, method, endpoint):
super().__init__(f'Unexpected reply for {method} from {endpoint}')
class RequestsError(requests.exceptions.RequestException): class RequestsError(requests.exceptions.RequestException):
""" """
Wrapper for requests lib exceptions Wrapper for requests lib exceptions

Loading…
Cancel
Save