mirror of
https://github.com/sartography/cr-connect-workflow.git
synced 2025-02-21 20:28:10 +00:00
This is a decent beginning framework for customer error messages.
It is not complete, but is in a state where we can start to interact with the front end. Two tests are failing. Committing so I can work on an error for Alex.
This commit is contained in:
parent
8a2a8b1443
commit
39eb5c5c21
@ -68,7 +68,7 @@ class ApiError(Exception):
|
|||||||
class ApiErrorSchema(ma.Schema):
|
class ApiErrorSchema(ma.Schema):
|
||||||
class Meta:
|
class Meta:
|
||||||
fields = ("code", "message", "workflow_name", "file_name", "task_name", "task_id",
|
fields = ("code", "message", "workflow_name", "file_name", "task_name", "task_id",
|
||||||
"task_data", "task_user")
|
"task_data", "task_user", "hint")
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(ApiError)
|
@app.errorhandler(ApiError)
|
||||||
|
@ -4,9 +4,12 @@
|
|||||||
# required_message - human readable message return to the user if error only occurs in required
|
# required_message - human readable message return to the user if error only occurs in required
|
||||||
# all_message -human readable message return to the user if error only occurs in all
|
# all_message -human readable message return to the user if error only occurs in all
|
||||||
#
|
#
|
||||||
known_errors = [{'key': 'Error is Non-default exclusive outgoing sequence flow without condition',
|
# known_errors = [{'key': 'Error is Non-default exclusive outgoing sequence flow without condition',
|
||||||
'message': 'Missing condition', 'hint': 'Add a Condition Type to your gateway path.'}]
|
# 'message': 'Missing condition', 'hint': 'Add a Condition Type to your gateway path.'}]
|
||||||
|
known_errors = {'Error is Non-default exclusive outgoing sequence flow without condition':
|
||||||
|
{'message': 'Missing condition', 'hint': 'Add a Condition Type to your gateway path.'}}
|
||||||
generic_message = """Workflow validation failed. For more information about the error, see below."""
|
generic_message = """Workflow validation failed. For more information about the error, see below."""
|
||||||
|
# error_keys = [error['key'] for error in known_errors]
|
||||||
|
|
||||||
class ValidationErrorService(object):
|
class ValidationErrorService(object):
|
||||||
|
|
||||||
@ -21,24 +24,37 @@ class ValidationErrorService(object):
|
|||||||
def interpret_validation_errors(errors):
|
def interpret_validation_errors(errors):
|
||||||
if len(errors) == 0:
|
if len(errors) == 0:
|
||||||
return ()
|
return ()
|
||||||
hint = ''
|
# hint = ''
|
||||||
|
interpreted_errors = []
|
||||||
|
|
||||||
for known_error in known_errors:
|
for error_type in ['all', 'required']:
|
||||||
if known_error['key'] in errors['all'].message:
|
if error_type in errors:
|
||||||
|
hint = generic_message
|
||||||
|
for known_key in known_errors:
|
||||||
|
if known_key in errors[error_type].message:
|
||||||
|
if 'hint' in known_errors[known_key]:
|
||||||
|
hint = known_errors[known_key]['hint']
|
||||||
|
# else:
|
||||||
|
# hint = generic_message
|
||||||
|
errors[error_type].hint = hint
|
||||||
|
interpreted_errors.append(errors[error_type])
|
||||||
|
|
||||||
# in both error all and error required
|
# for known_error in known_errors:
|
||||||
if known_error['key'] in errors['required'].message:
|
# if known_error['key'] in errors['all'].message:
|
||||||
if 'both_hint' in known_error.keys():
|
#
|
||||||
hint = known_error['both_hint']
|
# # in both error all and error required
|
||||||
if 'both_message' in known_error.keys():
|
# if known_error['key'] in errors['required'].message:
|
||||||
message = known_error['both_message']
|
# if 'hint' in known_error.keys():
|
||||||
|
# hint = known_error['hint']
|
||||||
|
# else:
|
||||||
|
# hint = generic_message
|
||||||
|
#
|
||||||
|
# # just in error all
|
||||||
|
# else:
|
||||||
|
# pass
|
||||||
|
#
|
||||||
|
# # just in error required
|
||||||
|
# if known_error['key'] in errors['required'].message:
|
||||||
|
# pass
|
||||||
|
|
||||||
# just in error all
|
return interpreted_errors
|
||||||
else:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# just in error required
|
|
||||||
if known_error['key'] in errors['required'].message:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return errors
|
|
||||||
|
@ -339,8 +339,8 @@ class WorkflowProcessor(object):
|
|||||||
spec = parser.get_spec(process_id)
|
spec = parser.get_spec(process_id)
|
||||||
except ValidationException as ve:
|
except ValidationException as ve:
|
||||||
raise ApiError(code="workflow_validation_error",
|
raise ApiError(code="workflow_validation_error",
|
||||||
message="Failed to parse Workflow Specification '%s'" % workflow_spec_id +
|
message="Failed to parse Workflow Specification '%s'. \n" % workflow_spec_id +
|
||||||
"Error is %s" % str(ve),
|
"Error is %s. \n" % str(ve),
|
||||||
file_name=ve.filename,
|
file_name=ve.filename,
|
||||||
task_id=ve.id,
|
task_id=ve.id,
|
||||||
tag=ve.tag)
|
tag=ve.tag)
|
||||||
|
@ -1,14 +1,20 @@
|
|||||||
from tests.base_test import BaseTest
|
from tests.base_test import BaseTest
|
||||||
|
from crc.services.workflow_service import WorkflowService
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
class TestCustomerError(BaseTest):
|
class TestCustomerError(BaseTest):
|
||||||
|
|
||||||
def test_customer_error(self):
|
def test_customer_error(self):
|
||||||
# workflow = self.create_workflow('failing_workflow')
|
# workflow = self.create_workflow('failing_workflow')
|
||||||
# workflow_api = self.get_workflow_api(workflow)
|
# workflow_api = self.get_workflow_api(workflow)
|
||||||
# first_task = workflow_api.next_task
|
# first_task = workflow_api.next_task
|
||||||
|
self.load_example_data()
|
||||||
spec_model = self.load_test_spec('failing_gateway_workflow')
|
spec_model = self.load_test_spec('failing_gateway_workflow')
|
||||||
|
# final_data = WorkflowService.test_spec(spec_model.id)
|
||||||
|
#
|
||||||
|
# spec_model = self.load_test_spec('failing_gateway_workflow')
|
||||||
rv = self.app.get('/v1.0/workflow-specification/%s/validate' % spec_model.id, headers=self.logged_in_headers())
|
rv = self.app.get('/v1.0/workflow-specification/%s/validate' % spec_model.id, headers=self.logged_in_headers())
|
||||||
json_data = json.loads(rv.get_data(as_text=True))
|
# json_data = json.loads(rv.get_data(as_text=True))
|
||||||
#
|
#
|
||||||
print('test_customer_error: ')
|
print('test_customer_error: ')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user