Skip to content

Instantly share code, notes, and snippets.

@mariopepe
Created January 23, 2022 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariopepe/20b90fd49edf5dba94757597d02324d0 to your computer and use it in GitHub Desktop.
Save mariopepe/20b90fd49edf5dba94757597d02324d0 to your computer and use it in GitHub Desktop.
error_object.dart
import 'package:equatable/equatable.dart';
import 'failures.dart';
class ErrorObject extends Equatable {
const ErrorObject({
required this.title,
required this.message,
});
final String title;
final String message;
@override
List<Object?> get props => [title, message];
/// Again, here I leverage the power of sealed_classes to write robust code and
/// make sure to map evey and each failure with a specific message to show in
/// the UI.
static ErrorObject mapFailureToErrorObject({required FailureEntity failure}) {
return failure.when(
serverFailure: () => const ErrorObject(
title: 'Error Code: INTERNAL_SERVER_FAILURE',
message: 'It seems that the server is not reachable at the moment, try '
'again later, should the issue persist please reach out to the '
'developer at a@b.com',
),
dataParsingFailure: () => const ErrorObject(
title: 'Error Code: JSON_PARSING_FAILURE',
message: 'It seems that the app needs to be updated to reflect the , '
'changed server data structure, if no update is '
'available on the store please reach out to the developer at a@b.com',
),
noConnectionFailure: () => const ErrorObject(
title: 'Error Code: NO_CONNECTIVITY',
message: 'It seems that your device is not connected to the network, '
'please check your internet connectivity or try again later.',
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment