formatFlashError function

String formatFlashError(
  1. Object error
)

Formats an expected Flash error into a concise user-facing message.

Implementation

String formatFlashError(Object error) {
  if (error is FlashApiException) {
    final hint = error.hint;
    return hint.isEmpty ? error.message : '${error.message}\n$hint';
  }
  if (error is SchemaVersionMismatchException) {
    return _stripExceptionPrefix(error.toString());
  }
  if (error is LocalValidatorException) {
    return error.message;
  }
  if (error is ValidatorFingerprintMismatchException) {
    return _stripExceptionPrefix(error.toString());
  }
  if (error is PipelineConfigException) {
    return error.message;
  }
  if (error is DslRunException) {
    return _stripExceptionPrefix(error.toString());
  }
  if (error is http.ClientException) {
    return 'Network request failed: ${error.message}';
  }
  if (error is SocketException) {
    return 'Network request failed: ${error.message}';
  }
  if (error is TimeoutException) {
    return 'Request timed out. Please try again.';
  }
  if (error is StateError) {
    return error.message;
  }
  if (error is ArgumentError) {
    final message = error.message;
    return message == null ? error.toString() : '$message';
  }
  return error.toString();
}