Creating a Failure

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

Make sure that the Failure objects extend the base Failure class of the codenic_exception_converter 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',
  });
}

Last updated