Skip to content

Commit 3dd2502

Browse files
committed
rest exception handlers
1 parent 3b70a42 commit 3dd2502

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import logging
2+
3+
from servicelib.aiohttp import status
4+
5+
from ...exception_handling import (
6+
ExceptionToHttpErrorMap,
7+
HttpErrorInfo,
8+
exception_handling_decorator,
9+
to_exceptions_handlers_map,
10+
)
11+
from ...folders.errors import FolderAccessForbiddenError, FolderNotFoundError
12+
from ...workspaces.errors import WorkspaceAccessForbiddenError, WorkspaceNotFoundError
13+
from ..exceptions import (
14+
ProjectDeleteError,
15+
ProjectInvalidRightsError,
16+
ProjectNotFoundError,
17+
ProjectOwnerNotFoundInTheProjectAccessRightsError,
18+
WrongTagIdsInQueryError,
19+
)
20+
21+
_logger = logging.getLogger(__name__)
22+
23+
_TO_HTTP_ERROR_MAP: ExceptionToHttpErrorMap = {
24+
#
25+
# NOTE: keep keys alphabetically sorted
26+
#
27+
FolderAccessForbiddenError: HttpErrorInfo(
28+
status.HTTP_403_FORBIDDEN,
29+
"Access to folder forbidden",
30+
),
31+
FolderNotFoundError: HttpErrorInfo(
32+
status.HTTP_404_NOT_FOUND,
33+
"Folder not found: {reason}",
34+
),
35+
ProjectDeleteError: HttpErrorInfo(
36+
status.HTTP_409_CONFLICT,
37+
"Failed to complete deletion of '{project_uuid}': {reason}",
38+
),
39+
ProjectInvalidRightsError: HttpErrorInfo(
40+
status.HTTP_403_FORBIDDEN,
41+
"Do not have sufficient access rights on project {project_uuid} for this action",
42+
),
43+
ProjectNotFoundError: HttpErrorInfo(
44+
status.HTTP_404_NOT_FOUND,
45+
"Project not found",
46+
),
47+
ProjectOwnerNotFoundInTheProjectAccessRightsError: HttpErrorInfo(
48+
status.HTTP_400_BAD_REQUEST,
49+
"Project owner identifier was not found in the project's access-rights field",
50+
),
51+
WorkspaceAccessForbiddenError: HttpErrorInfo(
52+
status.HTTP_403_FORBIDDEN,
53+
"Access to workspace forbidden: {reason}",
54+
),
55+
WorkspaceNotFoundError: HttpErrorInfo(
56+
status.HTTP_404_NOT_FOUND,
57+
"Workspace not found: {reason}",
58+
),
59+
WrongTagIdsInQueryError: HttpErrorInfo(
60+
status.HTTP_400_BAD_REQUEST,
61+
"Wrong tag IDs in query",
62+
),
63+
}
64+
65+
handle_plugin_requests_exceptions = exception_handling_decorator(
66+
to_exceptions_handlers_map(_TO_HTTP_ERROR_MAP)
67+
)

0 commit comments

Comments
 (0)