Skip to content
Snippets Groups Projects
Commit bd291c64 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Common:

- cosmetic changes in RPC method wrapper
parent b6b9d698
No related branches found
No related tags found
2 merge requests!54Release 2.0.0,!34Context Scalability extensions using CockroachDB + Removal of Stateful database inside Device + other
......@@ -18,8 +18,7 @@ from typing import Iterable, Union
class ServiceException(Exception):
def __init__(
self, code : grpc.StatusCode, details : str, extra_details : Union[str, Iterable[str]] = []
) -> None:
) -> None:
self.code = code
if isinstance(extra_details, str): extra_details = [extra_details]
self.details = '; '.join(map(str, [details] + extra_details))
......@@ -28,39 +27,34 @@ class ServiceException(Exception):
class NotFoundException(ServiceException):
def __init__(
self, object_name : str, object_uuid: str, extra_details : Union[str, Iterable[str]] = []
) -> None:
) -> None:
details = '{:s}({:s}) not found'.format(str(object_name), str(object_uuid))
super().__init__(grpc.StatusCode.NOT_FOUND, details, extra_details=extra_details)
class AlreadyExistsException(ServiceException):
def __init__(
self, object_name : str, object_uuid: str, extra_details : Union[str, Iterable[str]] = None
) -> None:
) -> None:
details = '{:s}({:s}) already exists'.format(str(object_name), str(object_uuid))
super().__init__(grpc.StatusCode.ALREADY_EXISTS, details, extra_details=extra_details)
class InvalidArgumentException(ServiceException):
def __init__(
self, argument_name : str, argument_value: str, extra_details : Union[str, Iterable[str]] = None
) -> None:
) -> None:
details = '{:s}({:s}) is invalid'.format(str(argument_name), str(argument_value))
super().__init__(grpc.StatusCode.INVALID_ARGUMENT, details, extra_details=extra_details)
class OperationFailedException(ServiceException):
def __init__(
self, operation : str, extra_details : Union[str, Iterable[str]] = None
) -> None:
) -> None:
details = 'Operation({:s}) failed'.format(str(operation))
super().__init__(grpc.StatusCode.INTERNAL, details, extra_details=extra_details)
class NotImplementedException(ServiceException):
def __init__(
self, operation : str, extra_details : Union[str, Iterable[str]] = None
) -> None:
) -> None:
details = 'Operation({:s}) not implemented'.format(str(operation))
super().__init__(grpc.StatusCode.UNIMPLEMENTED, details, extra_details=extra_details)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment