Skip to content

Commit d88292f

Browse files
authored
Update exception handling to support RpcErrors. (#72)
1 parent 0857da9 commit d88292f

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

btrdb/exceptions.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,21 @@ def handle_grpc_error(err):
117117
118118
Parameters
119119
----------
120-
err: grpc.RpcError
120+
err: Union[grpc.RpcError, btrdb.BTrDBError]
121121
"""
122122
details = err.details()
123-
if details == "[404] stream does not exist":
124-
raise StreamNotFoundError("Stream not found with provided uuid") from None
125-
elif details == "failed to connect to all addresses":
126-
raise ConnectionError("Failed to connect to BTrDB") from None
127-
elif any(str(e) in err.details() for e in BTRDB_SERVER_ERRORS):
128-
raise BTRDBServerError("An error has occured with btrdb-server") from None
129-
elif str(err.code()) == "StatusCode.PERMISSION_DENIED":
130-
raise PermissionDenied(details) from None
131-
raise BTrDBError(details) from None
123+
if isinstance(err, BTrDBError):
124+
if details == "[404] stream does not exist":
125+
raise StreamNotFoundError("Stream not found with provided uuid") from None
126+
elif details == "failed to connect to all addresses":
127+
raise ConnectionError("Failed to connect to BTrDB") from None
128+
elif any(str(e) in err.details() for e in BTRDB_SERVER_ERRORS):
129+
raise BTRDBServerError("An error has occured with btrdb-server") from None
130+
elif str(err.code()) == "StatusCode.PERMISSION_DENIED":
131+
raise PermissionDenied(details) from None
132+
raise BTrDBError(details) from None
133+
else:
134+
raise err
132135

133136

134137
def check_proto_stat(stat):

0 commit comments

Comments
 (0)