-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8078 from OpenMined/init_exception_handling
Init exception handling
- Loading branch information
Showing
6 changed files
with
50 additions
and
23 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# stdlib | ||
from typing import List | ||
from typing import Optional | ||
|
||
# relative | ||
from ..service.context import NodeServiceContext | ||
from ..service.response import SyftError | ||
from ..service.user.user_roles import ServiceRole | ||
|
||
|
||
class PySyftException(Exception): | ||
"""Base class for all PySyft exceptions.""" | ||
|
||
def __init__(self, message: str, roles: Optional[List[ServiceRole]] = None): | ||
super().__init__(message) | ||
self.message = message | ||
self.roles = roles if roles else [ServiceRole.ADMIN] | ||
|
||
def raise_with_context(self, context: NodeServiceContext): | ||
self.context = context | ||
return self | ||
|
||
def handle(self) -> SyftError: | ||
# if self.context and self.context.role in self.roles: | ||
return SyftError(message=self.message) | ||
# else: | ||
# return SyftError(message="Access denied to exception message.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# stdlib | ||
|
||
# relative | ||
from ..service.user.user_roles import ServiceRole | ||
from .exception import PySyftException | ||
|
||
UserAlreadyExistsException = PySyftException( | ||
message="User already exists", roles=[ServiceRole.ADMIN] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters