Codenic Clean Architecture
  • Introduction
  • The Clean Architecture
    • Presentation Layer
    • Domain Layer
    • Infrastructure Layer
  • Tutorial
    • Overview
    • Creating a Flutter Modular Project
      • Tips for Managing a Modular Project
    • Implementing the Domain Layer
      • Core Dependencies
      • Creating an Entity
      • Creating a Failure
      • Creating a Repository Interface
      • Creating Use Cases
        • CRUD Operations (Runner)
        • Data Streams (Watcher)
    • Implementing the Infrastructure Layer
      • External Dependencies
      • Creating a Data Model
      • Creating a Data Source
      • Implementing a Repository
    • Implementing the Presentation Layer
      • External Dependencies
      • Dependency Injection and Service Locator
      • Widgets
        • Snackbar Handler
        • Global Blocs Widget
        • Note Widgets
  • Packages
    • Codenic Bloc Use Case
      • Runner
      • Watcher
    • Codenic Logger
      • Usage
      • Example
      • Modifying the Logger
      • Integrating Firebase Crashlytics to the logger
    • Codenic Exception Converter
      • Failure Object
      • Exception Converter
      • Exception Converter Suite
      • Example
Powered by GitBook
On this page
  • 1. Create a Failure indicating that the note title has exceeded the max length
  • 2. Create a Failure indicating that the note content has exceeded the max length
  1. Tutorial
  2. Implementing the Domain Layer

Creating a Failure

PreviousCreating an EntityNextCreating a Repository Interface

Last updated 2 years ago

Let's create a couple of objects that describes the possible errors of the note feature.

Make sure that the Failure objects extend the base Failure class of the package. Later, this will give us access to utility tools for conveniently converting Exceptions into Failures.

Under the note_app/modules/domain/lib/note/failures/ directory, create the following Failure objects:

1. Create a Failure indicating that the note title has exceeded the max length

Make a file named note_title_too_long_failure.dart and add the following code:

import 'package:domain/domain.dart';
import 'package:domain/note/entities/note_entry.dart';

/// {@template NoteTitleTooLongFailure}
/// A failure representing a [NoteEntry.title] that has exceeded the maximum
/// length.
/// {@endtemplate}
class NoteTitleTooLongFailure extends Failure {
  /// {@macro NoteTitleTooLongFailure}
  const NoteTitleTooLongFailure({super.message = 'The note title is too long'});
}

2. Create a Failure indicating that the note content has exceeded the max length

Make a file named and note_content_too_long_failure.dart add the following code:

import 'package:domain/domain.dart';
import 'package:domain/note/entities/note_entry.dart';

/// {@template NoteContentTooLongFailure}
/// A failure representing a [NoteEntry.content] that has exceeded the maximum
/// length.
/// {@endtemplate}
class NoteContentTooLongFailure extends Failure {
  /// {@macro NoteContentTooLongFailure}
  const NoteContentTooLongFailure({
    super.message = 'The note content is too long',
  });
}

codenic_exception_converter
Failure