From e102214809add8f92a34293920379f66dea0c078 Mon Sep 17 00:00:00 2001 From: Dan Funk Date: Wed, 3 Jun 2020 15:03:22 -0400 Subject: [PATCH] minor cleanup of error codes. --- crc/api/file.py | 2 +- crc/api/study.py | 2 +- crc/api/tools.py | 8 ++++---- crc/services/file_service.py | 2 +- crc/services/lookup_service.py | 2 +- crc/services/protocol_builder.py | 2 +- crc/services/study_service.py | 4 ++-- crc/services/workflow_service.py | 6 +++--- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/crc/api/file.py b/crc/api/file.py index a537cfe5..5cf54221 100644 --- a/crc/api/file.py +++ b/crc/api/file.py @@ -122,7 +122,7 @@ def get_file_info(file_id): def update_file_info(file_id, body): if file_id is None: - raise ApiError('unknown_file', 'Please provide a valid File ID.') + raise ApiError('no_such_file', 'Please provide a valid File ID.') file_model = session.query(FileModel).filter_by(id=file_id).first() diff --git a/crc/api/study.py b/crc/api/study.py index e9a251f8..8fdd1b4a 100644 --- a/crc/api/study.py +++ b/crc/api/study.py @@ -50,7 +50,7 @@ def update_study(study_id, body): def get_study(study_id): study = StudyService.get_study(study_id) if (study is None): - raise ApiError("Study not found", status_code=404) + raise ApiError("unknown_study", 'The study "' + study_id + '" is not recognized.', status_code=404) return StudySchema().dump(study) diff --git a/crc/api/tools.py b/crc/api/tools.py index 6fb31b71..4699be5f 100644 --- a/crc/api/tools.py +++ b/crc/api/tools.py @@ -20,9 +20,9 @@ def render_markdown(data, template): data = json.loads(data) return template.render(**data) except UndefinedError as ue: - raise ApiError(code="undefined field", message=ue.message) + raise ApiError(code="undefined_field", message=ue.message) except Exception as e: - raise ApiError(code="invalid", message=str(e)) + raise ApiError(code="invalid_render", message=str(e)) def render_docx(): @@ -42,9 +42,9 @@ def render_docx(): cache_timeout=-1 # Don't cache these files on the browser. ) except ValueError as e: - raise ApiError(code="invalid", message=str(e)) + raise ApiError(code="undefined_field", message=str(e)) except Exception as e: - raise ApiError(code="invalid", message=str(e)) + raise ApiError(code="invalid_render", message=str(e)) def list_scripts(): diff --git a/crc/services/file_service.py b/crc/services/file_service.py index 9142a7c3..ce4b7261 100644 --- a/crc/services/file_service.py +++ b/crc/services/file_service.py @@ -274,7 +274,7 @@ class FileService(object): workflow_spec_model = FileService.find_spec_model_in_db(workflow) if workflow_spec_model is None: - raise ApiError(code="workflow_model_error", + raise ApiError(code="unknown_workflow", message="Something is wrong. I can't find the workflow you are using.") file_data_model = session.query(FileDataModel) \ diff --git a/crc/services/lookup_service.py b/crc/services/lookup_service.py index 076fbe9a..71424b6b 100644 --- a/crc/services/lookup_service.py +++ b/crc/services/lookup_service.py @@ -103,7 +103,7 @@ class LookupService(object): workflow_id=workflow_model.id, name=file_name) if len(latest_files) < 1: - raise ApiError("missing_file", "Unable to locate the lookup data file '%s'" % file_name) + raise ApiError("invalid_enum", "Unable to locate the lookup data file '%s'" % file_name) else: data_model = latest_files[0] diff --git a/crc/services/protocol_builder.py b/crc/services/protocol_builder.py index 5fc5535f..8d1d7886 100644 --- a/crc/services/protocol_builder.py +++ b/crc/services/protocol_builder.py @@ -25,7 +25,7 @@ class ProtocolBuilderService(object): def get_studies(user_id) -> {}: ProtocolBuilderService.__enabled_or_raise() if not isinstance(user_id, str): - raise ApiError("invalid_user_id", "This user id is invalid: " + str(user_id)) + raise ApiError("protocol_builder_error", "This user id is invalid: " + str(user_id)) response = requests.get(ProtocolBuilderService.STUDY_URL % user_id) if response.ok and response.text: pb_studies = ProtocolBuilderStudySchema(many=True).loads(response.text) diff --git a/crc/services/study_service.py b/crc/services/study_service.py index 8d9df0db..0bc80bcf 100644 --- a/crc/services/study_service.py +++ b/crc/services/study_service.py @@ -319,9 +319,9 @@ class StudyService(object): try: StudyService._create_workflow_model(study_model, workflow_spec) except WorkflowTaskExecException as wtee: - errors.append(ApiError.from_task("workflow_execution_exception", str(wtee), wtee.task)) + errors.append(ApiError.from_task("workflow_startup_exception", str(wtee), wtee.task)) except WorkflowException as we: - errors.append(ApiError.from_task_spec("workflow_execution_exception", str(we), we.sender)) + errors.append(ApiError.from_task_spec("workflow_startup_exception", str(we), we.sender)) return errors @staticmethod diff --git a/crc/services/workflow_service.py b/crc/services/workflow_service.py index c3834f0a..5efa8cab 100644 --- a/crc/services/workflow_service.py +++ b/crc/services/workflow_service.py @@ -82,7 +82,7 @@ class WorkflowService(object): processor = WorkflowProcessor(workflow_model, validate_only=True) except WorkflowException as we: WorkflowService.delete_test_data() - raise ApiError.from_workflow_exception("workflow_execution_exception", str(we), we) + raise ApiError.from_workflow_exception("workflow_validation_exception", str(we), we) while not processor.bpmn_workflow.is_completed(): try: @@ -96,7 +96,7 @@ class WorkflowService(object): task.complete() except WorkflowException as we: WorkflowService.delete_test_data() - raise ApiError.from_workflow_exception("workflow_execution_exception", str(we), we) + raise ApiError.from_workflow_exception("workflow_validation_exception", str(we), we) WorkflowService.delete_test_data() return processor.bpmn_workflow.last_task.data @@ -162,7 +162,7 @@ class WorkflowService(object): options.append({"id": d.value, "label": d.label}) return random.choice(options) else: - raise ApiError.from_task("invalid_autocomplete", "The settings for this auto complete field " + raise ApiError.from_task("unknown_lookup_option", "The settings for this auto complete field " "are incorrect: %s " % field.id, task) elif field.type == "long": return random.randint(1, 1000)