Skip to content

Update exception handling to support RpcErrors. #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions btrdb/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,21 @@ def handle_grpc_error(err):

Parameters
----------
err: grpc.RpcError
err: Union[grpc.RpcError, btrdb.BTrDBError]
"""
details = err.details()
if details == "[404] stream does not exist":
raise StreamNotFoundError("Stream not found with provided uuid") from None
elif details == "failed to connect to all addresses":
raise ConnectionError("Failed to connect to BTrDB") from None
elif any(str(e) in err.details() for e in BTRDB_SERVER_ERRORS):
raise BTRDBServerError("An error has occured with btrdb-server") from None
elif str(err.code()) == "StatusCode.PERMISSION_DENIED":
raise PermissionDenied(details) from None
raise BTrDBError(details) from None
if isinstance(err, BTrDBError):
if details == "[404] stream does not exist":
raise StreamNotFoundError("Stream not found with provided uuid") from None
elif details == "failed to connect to all addresses":
raise ConnectionError("Failed to connect to BTrDB") from None
elif any(str(e) in err.details() for e in BTRDB_SERVER_ERRORS):
raise BTRDBServerError("An error has occured with btrdb-server") from None
elif str(err.code()) == "StatusCode.PERMISSION_DENIED":
raise PermissionDenied(details) from None
raise BTrDBError(details) from None
else:
raise err


def check_proto_stat(stat):
Expand Down