forked from Zipstack/unstract
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.py
More file actions
84 lines (61 loc) · 2.2 KB
/
Copy pathexceptions.py
File metadata and controls
84 lines (61 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from typing import Optional
from adapter_processor.constants import AdapterKeys
from rest_framework.exceptions import APIException
class IdIsMandatory(APIException):
status_code = 400
default_detail = "ID is Mandatory."
class InValidType(APIException):
status_code = 400
default_detail = "Type is not Valid."
class InValidAdapterId(APIException):
status_code = 400
default_detail = "Adapter ID is not Valid."
class InvalidEncryptionKey(APIException):
status_code = 403
default_detail = (
"Platform encryption key for storing adapter credentials has changed! "
"Please inform the organization admin to contact support."
)
class InternalServiceError(APIException):
status_code = 500
default_detail = "Internal Service error"
class CannotDeleteDefaultAdapter(APIException):
status_code = 500
default_detail = (
"This is configured as default and cannot be deleted. "
"Please configure a different default before you try again!"
)
class DuplicateAdapterNameError(APIException):
status_code = 400
default_detail: str = AdapterKeys.ADAPTER_NAME_EXISTS
def __init__(
self,
name: Optional[str] = None,
detail: Optional[str] = None,
code: Optional[str] = None,
) -> None:
if name:
detail = self.default_detail.replace("this name", f"name '{name}'")
super().__init__(detail, code)
class TestAdapterError(APIException):
status_code = 500
default_detail = "Error while testing adapter"
class TestAdapterInputError(APIException):
status_code = 400
default_detail = "Error while testing adapter, please check the configuration."
class DeleteAdapterInUseError(APIException):
status_code = 409
def __init__(
self,
detail: Optional[str] = None,
code: Optional[str] = None,
adapter_name: str = "adapter",
):
if detail is None:
if adapter_name != "adapter":
adapter_name = f"'{adapter_name}'"
detail = (
f"Cannot delete {adapter_name}. "
"It is used in a workflow or a prompt studio project"
)
super().__init__(detail, code)