def translate_error(error, translation_list, format_str=None):
  """Translates error or returns original error if no matches.

  Note, an error will be translated if it is a child class of a value in
  translation_list. Also, translations earlier in the list take priority.

  Args:
    error (Exception): Error to translate.
    translation_list (list): List of (Exception, Exception) tuples. Translates
      errors that are instances of first error type to second. If there is a
      hierarchy, error types earlier in list are translated first.
    format_str (str|None): An api_lib.util.exceptions.FormattableErrorPayload
      format string. Note that any properties that are accessed here are on the
      FormattableErrorPayload object, not the object returned from the server.

  Returns:
    Error (Exception). Translated if match. Else, original error.
  """
  for untranslated_error, translated_error in translation_list:
    if isinstance(error, untranslated_error):
      return translated_error(error, format_str)
  return error