diff --git a/crc/api/common.py b/crc/api/common.py index 22bd04b5..05d81dd3 100644 --- a/crc/api/common.py +++ b/crc/api/common.py @@ -1,3 +1,5 @@ +import json + from SpiffWorkflow import WorkflowException from SpiffWorkflow.exceptions import WorkflowTaskExecException from flask import g @@ -88,6 +90,15 @@ class ApiErrorSchema(ma.Schema): @app.errorhandler(ApiError) def handle_invalid_usage(error): response = ApiErrorSchema().dump(error) + + # In the unlikely event that the API error can't be serialized, try removing the task_data, as it may + # contain some invalid data that we can't return, so we can at least get the erro rmessage. + try: + json_output = json.dumps(response) + except TypeError as te: + error.task_data = {'task_data_hidden':'We were unable to serialize the task data when reporting this error'} + response = ApiErrorSchema().dump(error) + return response, error.status_code