open-craft/xblock-poll

Improve message display in case of error on "export to csv"

alfredchavez opened this issue · 0 comments

With the new change on error display when export to csv button is used, I could see that when a task was successful and contained an error, it will display to the user the whole error, like this:
Error: Unexpected result: {'error': 'error!', 'report_filename': 'poll-data-export-2021-07-08-222643.csv', 'start_timestamp': 1625783203.2447248, 'generation_time_s': 0.018067359924316406}
which is caused by the way we keep this results(as a string with "Unexpected results: " added):

if task_result.successful():
    if isinstance(task_result.result, dict) and not task_result.result.get('error'):
        self.last_export_result = task_result.result
    else:
        self.last_export_result = {'error': u'Unexpected result: {}'.format(repr(task_result.result))} # <-- 
else:
    self.last_export_result = {'error': six.text_type(task_result.result)}

I think that would be better to send to json to the frontend instead of the repr and process it in the frontend itself showing just the "error" part to the user and logging the rest to the browser console