18
18
HttpRequestNodeTimeout ,
19
19
Response ,
20
20
)
21
+ from .exc import (
22
+ AuthorizationConfigError ,
23
+ FileFetchError ,
24
+ InvalidHttpMethodError ,
25
+ ResponseSizeError ,
26
+ )
21
27
22
28
BODY_TYPE_TO_CONTENT_TYPE = {
23
29
"json" : "application/json" ,
@@ -51,7 +57,7 @@ def __init__(
51
57
# If authorization API key is present, convert the API key using the variable pool
52
58
if node_data .authorization .type == "api-key" :
53
59
if node_data .authorization .config is None :
54
- raise ValueError ("authorization config is required" )
60
+ raise AuthorizationConfigError ("authorization config is required" )
55
61
node_data .authorization .config .api_key = variable_pool .convert_template (
56
62
node_data .authorization .config .api_key
57
63
).text
@@ -116,7 +122,7 @@ def _init_body(self):
116
122
file_selector = data [0 ].file
117
123
file_variable = self .variable_pool .get_file (file_selector )
118
124
if file_variable is None :
119
- raise ValueError (f"cannot fetch file with selector { file_selector } " )
125
+ raise FileFetchError (f"cannot fetch file with selector { file_selector } " )
120
126
file = file_variable .value
121
127
self .content = file_manager .download (file )
122
128
case "x-www-form-urlencoded" :
@@ -155,12 +161,12 @@ def _assembling_headers(self) -> dict[str, Any]:
155
161
headers = deepcopy (self .headers ) or {}
156
162
if self .auth .type == "api-key" :
157
163
if self .auth .config is None :
158
- raise ValueError ("self.authorization config is required" )
164
+ raise AuthorizationConfigError ("self.authorization config is required" )
159
165
if authorization .config is None :
160
- raise ValueError ("authorization config is required" )
166
+ raise AuthorizationConfigError ("authorization config is required" )
161
167
162
168
if self .auth .config .api_key is None :
163
- raise ValueError ("api_key is required" )
169
+ raise AuthorizationConfigError ("api_key is required" )
164
170
165
171
if not authorization .config .header :
166
172
authorization .config .header = "Authorization"
@@ -183,7 +189,7 @@ def _validate_and_parse_response(self, response: httpx.Response) -> Response:
183
189
else dify_config .HTTP_REQUEST_NODE_MAX_TEXT_SIZE
184
190
)
185
191
if executor_response .size > threshold_size :
186
- raise ValueError (
192
+ raise ResponseSizeError (
187
193
f'{ "File" if executor_response .is_file else "Text" } size is too large,'
188
194
f' max size is { threshold_size / 1024 / 1024 :.2f} MB,'
189
195
f' but current size is { executor_response .readable_size } .'
@@ -196,7 +202,7 @@ def _do_http_request(self, headers: dict[str, Any]) -> httpx.Response:
196
202
do http request depending on api bundle
197
203
"""
198
204
if self .method not in {"get" , "head" , "post" , "put" , "delete" , "patch" }:
199
- raise ValueError (f"Invalid http method { self .method } " )
205
+ raise InvalidHttpMethodError (f"Invalid http method { self .method } " )
200
206
201
207
request_args = {
202
208
"url" : self .url ,
0 commit comments