Created
January 23, 2022 15:16
-
-
Save mariopepe/20b90fd49edf5dba94757597d02324d0 to your computer and use it in GitHub Desktop.
error_object.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 [email protected]', | |
), | |
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 [email protected]', | |
), | |
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