code: def handle_query_error(msg, query, session, payload=None):
      
      payload = payload or {}
      troubleshooting_link = config['TROUBLESHOOTING_LINK']
      query.error_message = msg
      query.status = QueryStatus.FAILED
      query.tmp_table_name = None
      session.commit()
      payload.update({
          'status': query.status,
          'error': msg,
      })
      if troubleshooting_link:
          payload['link'] = troubleshooting_link
      return payload
docs: Local method handling error while processing the SQL