-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
171 additions
and
74 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,21 +1,55 @@ | ||
__all__ = ["RepositoryException", "IntegrityError", "NotFoundError", "MultipleRecordsError"] | ||
import typing as t | ||
|
||
|
||
class RepositoryException(Exception): | ||
... | ||
__all__ = [ | ||
"Empty", | ||
"RepositoryException", | ||
"IntegrityError", | ||
"NotFoundError", | ||
"AlreadyExistsError", | ||
"MultipleRecordsError", | ||
] | ||
|
||
|
||
class Empty(Exception): | ||
... | ||
|
||
|
||
class IntegrityError(RepositoryException): | ||
class RepositoryException(Exception): | ||
... | ||
|
||
|
||
class NotFoundError(RepositoryException): | ||
... | ||
class ResourceException(RepositoryException): | ||
_error_message: t.ClassVar[str] = "exception" | ||
|
||
def __init__(self, *, resource: str, id: t.Any = None, detail: str = "") -> None: | ||
super().__init__() | ||
self.resource = resource | ||
self.id = id | ||
self.detail = detail | ||
|
||
class MultipleRecordsError(RepositoryException): | ||
... | ||
def __str__(self) -> str: | ||
return ( | ||
f"Resource '{self.resource}'" | ||
+ (f" ({self.id})" if self.id else "") | ||
+ f" {self._error_message}" | ||
+ (f" ({self.detail})" if self.detail else "") | ||
) | ||
|
||
def __repr__(self) -> str: | ||
return f'{self.__class__.__name__}("{self.__str__()}")' | ||
|
||
|
||
class IntegrityError(ResourceException): | ||
_error_message = "integrity failed" | ||
|
||
|
||
class NotFoundError(ResourceException): | ||
_error_message = "not found" | ||
|
||
|
||
class AlreadyExistsError(ResourceException): | ||
_error_message = "already exists" | ||
|
||
|
||
class MultipleRecordsError(ResourceException): | ||
_error_message = "multiple records found" |
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
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
Oops, something went wrong.