Just a quick hot fix so that when can still report errors back to the UI even when the task_data can't be serialized, which can happen when functions are defined.

This commit is contained in:
Dan 2021-08-12 12:49:19 -04:00
parent 40727c7ce6
commit 000de03733

View File

@ -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