Skip to content

패턴 및 규칙(Result, AppException...) ⭐️

Okhyeon Kim edited this page Apr 25, 2025 · 1 revision

Result Pattern

@freezed
sealed class Result<T> with _$Result<T> {
  const factory Result.success(T data) = Success<T>;
  const factory Result.error(Failure failure) = Error<T>;
}

AppException

@freezed
sealed class AppException with _$AppException implements Exception {
  const AppException._();

  const factory AppException.network({
    required String message,
    Object? error,
    StackTrace? stackTrace,
  }) = NetworkException;

  const factory AppException.api({
    required String message,
    int? statusCode,
    Object? error,
    StackTrace? stackTrace,
  }) = ApiException;

  const factory AppException.parsing({
    required String message,
    Object? error,
    StackTrace? stackTrace,
  }) = ParsingException;

  const factory AppException.database({
    required String message,
    Object? error,
    StackTrace? stackTrace,
  }) = DatabaseException;
  //...
}
Clone this wiki locally