dataOrThrowFirstValidationError<T> function

T dataOrThrowFirstValidationError<T>(
  1. Result<T> result
)

Implementation

T dataOrThrowFirstValidationError<T>(Result<T> result) {
  if (result is Success<T>) {
    return result.data;
  } else if (result is ValidationError<T>) {
    throw ValueError(result.first().message ?? '');
  } else if (result is ServerError<T>) {
    throw ValueError((result.data.subErrors.isNotEmpty
            ? result.first().message
            : result.data.message) ??
        "Server error, this is on us, we're looking into it.");
  } else {
    throw ValueError('Unknown error occurred, please try again later.');
  }
}