@@ -51,17 +51,20 @@ def run(self, command: Command) -> Result:
51
51
except DotHttpException as exc :
52
52
logger .error (f"dothttp exception happened { exc } " , exc_info = True )
53
53
result = Result (
54
- id = command .id , result = {"error_message" : exc .message , "error" : True }
54
+ id = command .id , result = {
55
+ "error_message" : exc .message , "error" : True }
55
56
)
56
57
except RequestException as exc :
57
58
logger .error (f"exception from requests { exc } " , exc_info = True )
58
59
result = Result (
59
- id = command .id , result = {"error_message" : str (exc ), "error" : True }
60
+ id = command .id , result = {
61
+ "error_message" : str (exc ), "error" : True }
60
62
)
61
63
except Exception as exc :
62
64
logger .error (f"unknown error happened { exc } " , exc_info = True )
63
65
result = Result (
64
- id = command .id , result = {"error_message" : str (exc ), "error" : True }
66
+ id = command .id , result = {
67
+ "error_message" : str (exc ), "error" : True }
65
68
)
66
69
return result
67
70
@@ -71,14 +74,14 @@ def execute(self, command):
71
74
req = self .get_curl_comp (config )
72
75
result = req .get_curl_output ()
73
76
result = Result (
74
- id = command .id ,
75
- result = {
76
- "body" : result ,
77
- "headers" : {
78
- "Content-Type" : mimetypes .types_map [".sh" ],
79
- },
77
+ id = command .id ,
78
+ result = {
79
+ "body" : result ,
80
+ "headers" : {
81
+ "Content-Type" : mimetypes .types_map [".sh" ],
80
82
},
81
- )
83
+ },
84
+ )
82
85
else :
83
86
comp = self .get_request_comp (config )
84
87
result = self .get_request_result (command , comp )
@@ -94,7 +97,8 @@ def get_config(self, command):
94
97
target = params .get ("target" , "1" )
95
98
nocookie = params .get ("nocookie" , False )
96
99
curl = params .get ("curl" , False )
97
- properties = [f"{ i } ={ j } " for i , j in params .get ("properties" , {}).items ()]
100
+ properties = [f"{ i } ={ j } " for i ,
101
+ j in params .get ("properties" , {}).items ()]
98
102
content = params .get ("content" , None )
99
103
contexts = params .get ("contexts" )
100
104
property_file = params .get ("property-file" , None )
@@ -123,6 +127,26 @@ def get_config(self, command):
123
127
124
128
def get_request_result (self , command , comp : RequestCompiler ):
125
129
comp .load_def ()
130
+ if comp .property_util .errors :
131
+ return Result (
132
+ id = command .id ,
133
+ result = {
134
+ "errors" : [{"var" : list (error .kwargs ['var' ]), "message" : str (error )} for error in comp .property_util .errors ],
135
+ "response" : {
136
+ "body" : "" ,
137
+ "output_file" : "" ,
138
+ "status" : 0 ,
139
+ "method" : "ERROR" ,
140
+ "url" : "ERROR" ,
141
+ "headers" : {
142
+ "Content-Type" : "text/plain" ,
143
+ },
144
+ "error" : True ,
145
+ "error_message" : "errors found" ,
146
+ "contentType" : "text/plain" ,
147
+ },
148
+ },
149
+ )
126
150
resp = comp .get_response ()
127
151
if output := comp .httpdef .output :
128
152
# body = f"Output stored in {output}"
@@ -131,7 +155,8 @@ def get_request_result(self, command, comp: RequestCompiler):
131
155
except Exception as e :
132
156
output = f"Not!. unhandled error happened : { e } "
133
157
logger .warning ("unable to write because" , exc_info = True )
134
- script_result = comp .script_execution .execute_test_script (resp ).as_json ()
158
+ script_result = comp .script_execution .execute_test_script (
159
+ resp ).as_json ()
135
160
body = resp .text
136
161
response_data = {
137
162
"response" : {
@@ -140,6 +165,7 @@ def get_request_result(self, command, comp: RequestCompiler):
140
165
** self ._get_resp_data (resp ),
141
166
},
142
167
"script_result" : script_result ,
168
+ "errors" : [error .kwargs for error in comp .property_util .errors ],
143
169
}
144
170
if resp .history :
145
171
response_data ["history" ] = [
@@ -153,9 +179,11 @@ def get_request_result(self, command, comp: RequestCompiler):
153
179
# redirects can add cookies
154
180
comp .httpdef .headers ["cookie" ] = resp .request .headers ["cookie" ]
155
181
try :
156
- data .update ({"http" : self .get_http_from_req (comp .httpdef , comp .property_util )})
182
+ data .update ({"http" : self .get_http_from_req (
183
+ comp .httpdef , comp .property_util )})
157
184
except Exception as e :
158
- logger .error ("ran into error regenerating http def from parsed object" )
185
+ logger .error (
186
+ "ran into error regenerating http def from parsed object" )
159
187
data .update (
160
188
{"http" : f"ran into error \n Exception: `{ e } ` message:{ e .args } " }
161
189
)
@@ -175,7 +203,8 @@ def get_request_comp(self, config):
175
203
176
204
@staticmethod
177
205
def get_http_from_req (request : HttpDef , property_util : "PropertyProvider" ):
178
- http_def = MultidefHttp (import_list = [], allhttps = [request .get_http_from_req ()])
206
+ http_def = MultidefHttp (import_list = [], allhttps = [
207
+ request .get_http_from_req ()])
179
208
return HttpFileFormatter .format (http_def , property_util = property_util )
180
209
181
210
@@ -200,7 +229,8 @@ def load_model(self):
200
229
##
201
230
# context has varibles defined
202
231
# for resolving purpose, including them into content
203
- self .content = self .content + CONTEXT_SEP + CONTEXT_SEP .join (self .args .contexts )
232
+ self .content = self .content + CONTEXT_SEP + \
233
+ CONTEXT_SEP .join (self .args .contexts )
204
234
205
235
def select_target (self ):
206
236
for context in self .args .contexts :
@@ -219,7 +249,7 @@ def select_target(self):
219
249
self .model .import_list = model .import_list
220
250
self .load_imports ()
221
251
self .content += context + "\n \n " + context
222
-
252
+
223
253
except Exception as e :
224
254
# contexts, can not always be correct syntax
225
255
# in such scenarios, don't complain, try to resolve with
@@ -277,19 +307,20 @@ def run(self, command: Command) -> Result:
277
307
"headers" : {
278
308
"Content-Type" : "text/plain" ,
279
309
},
280
- "output_file" :"" ,
310
+ "output_file" : "" ,
281
311
"error" : True ,
282
312
"error_message" : error_result ,
283
313
"contentType" : "text/plain" ,
284
314
}
285
315
result = {
286
316
"response" : response ,
287
- "script_result" : {"stdout" : "" , "error" : "" , "properties" :{}, "tests" :[]},
317
+ "script_result" : {"stdout" : "" , "error" : "" , "properties" : {}, "tests" : []},
288
318
"http" : "REQUEST_EXECUTION_ERROR" ,
289
319
"filenameExtension" : ".txt" ,
290
320
}
291
321
result .update (response )
292
- return Result (id = command .id , result = result )
322
+ return Result (id = command .id , result = result )
323
+
293
324
294
325
class FormatHttpFileHandler (BaseHandler ):
295
326
method = "/file/format"
@@ -301,6 +332,7 @@ def run(self, command: Command) -> Result:
301
332
result = Result (id = command .id , result = command .params )
302
333
return result
303
334
335
+
304
336
class ResolveBase ():
305
337
306
338
def get_resolved (self , command : Command ) -> Result :
@@ -320,7 +352,7 @@ def get_resolved(self, command: Command) -> Result:
320
352
if match .start () <= pos <= match .end ():
321
353
property_hovered = match .group ()[2 :- 2 ].split ("=" )[0 ].strip ()
322
354
break
323
-
355
+
324
356
type_dict = TypeFromPos .figure_n_get (model , pos )
325
357
if "target" not in type_dict :
326
358
command .params ["target" ] = 1
@@ -363,12 +395,14 @@ def get_resolved(self, command: Command) -> Result:
363
395
return Result (id = command .id , result = type_dict )
364
396
365
397
# return resolved string instead of model object
398
+
399
+
366
400
class GetHoveredResolvedParamFileHandler (RunHttpFileHandler , ResolveBase ):
367
401
method = "/file/resolve"
368
402
369
403
def get_method (self ):
370
404
return GetHoveredResolvedParamFileHandler .method
371
-
405
+
372
406
def run (self , command ):
373
407
return self .get_resolved (command )
374
408
@@ -382,6 +416,7 @@ def get_method(self):
382
416
def run (self , command ):
383
417
return self .get_resolved (command )
384
418
419
+
385
420
class GetNameReferencesHandler (BaseHandler ):
386
421
name = "/file/names"
387
422
@@ -394,7 +429,8 @@ def run(self, command: Command) -> Result:
394
429
result = self .execute (command , filename )
395
430
except DotHttpException as ex :
396
431
result = Result (
397
- id = command .id , result = {"error_message" : ex .message , "error" : True }
432
+ id = command .id , result = {
433
+ "error_message" : ex .message , "error" : True }
398
434
)
399
435
except Exception as e :
400
436
result = Result (
@@ -428,7 +464,8 @@ def parse_n_get(self, http_data, filename: str):
428
464
for new_model , _content in BaseModelProcessor ._get_models_from_import (
429
465
model , filename
430
466
):
431
- self .get_for_http (new_model .allhttps , imported_names , imported_urls )
467
+ self .get_for_http (new_model .allhttps ,
468
+ imported_names , imported_urls )
432
469
return all_names , all_urls , imported_names , imported_urls
433
470
434
471
def get_for_http (self , allhttps , all_names , all_urls ):
0 commit comments