workflows: write connection error info to associated varname (#27511)
This commit is contained in:
parent
ee3ebb521f
commit
13383f60c1
|
@ -1747,7 +1747,17 @@ def test_webservice_call_error_handling(http_requests, pub):
|
|||
item.record_errors = True
|
||||
item.action_on_network_errors = ':pass'
|
||||
item.perform(formdata)
|
||||
assert not formdata.workflow_data
|
||||
|
||||
# connection error, with varname
|
||||
item = WebserviceCallStatusItem()
|
||||
item.url = 'http://remote.example.net/connection-error'
|
||||
item.varname = 'plop'
|
||||
item.record_errors = True
|
||||
item.action_on_network_errors = ':pass'
|
||||
item.perform(formdata)
|
||||
assert formdata.evolution[-1].parts[-1].summary == 'ConnectionError: error\n'
|
||||
assert formdata.workflow_data['plop_connection_error'] == 'error'
|
||||
|
||||
def test_webservice_call_store_in_backoffice_filefield(http_requests, pub):
|
||||
wf = Workflow(name='wscall to backoffice file field')
|
||||
|
|
|
@ -274,6 +274,10 @@ class WebserviceCallStatusItem(WorkflowStatusItem):
|
|||
# misconfigured action
|
||||
return
|
||||
|
||||
workflow_data = {}
|
||||
if self.varname:
|
||||
workflow_data['%s_time' % self.varname] = datetime.datetime.now().isoformat()
|
||||
|
||||
try:
|
||||
response, status, data = call_webservice(
|
||||
url=self.url,
|
||||
|
@ -285,6 +289,10 @@ class WebserviceCallStatusItem(WorkflowStatusItem):
|
|||
formdata=formdata)
|
||||
except ConnectionError as e:
|
||||
status = 0
|
||||
if self.varname:
|
||||
workflow_data['%s_connection_error' % self.varname] = str(e)
|
||||
formdata.update_workflow_data(workflow_data)
|
||||
formdata.store()
|
||||
self.action_on_error(self.action_on_network_errors, formdata,
|
||||
exc_info=sys.exc_info())
|
||||
return
|
||||
|
@ -307,11 +315,10 @@ class WebserviceCallStatusItem(WorkflowStatusItem):
|
|||
app_error_code = d['err']
|
||||
|
||||
if self.varname:
|
||||
workflow_data = {
|
||||
workflow_data.update({
|
||||
'%s_status' % self.varname: status,
|
||||
'%s_time' % self.varname: datetime.datetime.now().isoformat(),
|
||||
'%s_app_error_code' % self.varname: app_error_code,
|
||||
}
|
||||
})
|
||||
if app_error_code_header:
|
||||
workflow_data['%s_app_error_header' % self.varname] = app_error_code_header
|
||||
if status in (204, 205):
|
||||
|
|
Loading…
Reference in New Issue