import re


def ParseErrorDetail(e):
  """Parse <Message> and/or <Details> text from XML content.

  Args:
    e: The GSResponseError that includes XML to be parsed.

  Returns:
    (exception_name, m, d), where m is <Message> text or None,
                            and d is <Details> text or None.
  """
  exc_name_parts = re.split("[\.']", str(type(e)))
  if len(exc_name_parts) < 2:
    # Shouldn't happen, but have fallback in case.
    exc_name = str(type(e))
  else:
    exc_name = exc_name_parts[-2]
  if not hasattr(e, 'body') or e.body is None:
    return (exc_name, None)

  match = re.search(r'<Message>(?P<message>.*)</Message>', e.body)
  m = match.group('message') if match else None
  match = re.search(r'<Details>(?P<details>.*)</Details>', e.body)
  d = match.group('details') if match else None
  return (exc_name, m, d)