stripAuthExpiredMarker function

String stripAuthExpiredMarker(
  1. String formattedError
)

Removes the auth-expired marker (and surrounding whitespace) from the formatted error, leaving the human-readable part for display.

Implementation

String stripAuthExpiredMarker(String formattedError) {
  final start = formattedError.indexOf(authExpiredMarkerPrefix);
  if (start < 0) return formattedError;
  final close = formattedError.indexOf(
    ']]',
    start + authExpiredMarkerPrefix.length,
  );
  if (close < 0) return formattedError;
  final end = close + 2;
  // Strip trailing whitespace before the marker too.
  var cut = start;
  while (cut > 0 && formattedError[cut - 1] == ' ') {
    cut--;
  }
  return formattedError.substring(0, cut) + formattedError.substring(end);
}