code: def _extract_msg_from_last_exception():
      ''' Extract a useful error message from the last thrown exception '''
      last_exc_type, last_error, last_traceback = sys.exc_info()
      if isinstance(last_error, exceptions.DXAPIError):
          # Using the same code path as below would not
          # produce a useful message when the error contains a
          # 'details' hash (which would have a last line of
          # '}')
          return last_error.error_message()
      else:
          return traceback.format_exc().splitlines()[-1].strip(f _extract_msg_from_last_exception():
      ''' Extract a useful error message from the last thrown exception '''
      last_exc_type, last_error, last_traceback = sys.exc_info()
      if isinstance(last_error, exceptions.DXAPIError):
          # Using the same code path as below would not
          # produce a useful message when the error contains a
          # 'details' hash (which would have a last line of
          # '}')
          return last_error.error_message()
      else:
          return traceback.format_exc().splitlines()[-1].strip()
docs: Extract a useful error message from the last thrown exception