relatica/lib/models/exec_error.dart

30 wiersze
670 B
Dart
Czysty Zwykły widok Historia

import 'package:result_monad/result_monad.dart';
2022-11-09 02:19:44 +00:00
class ExecError {
final ErrorType type;
final String message;
ExecError({required this.type, this.message = ''});
@override
String toString() {
return 'ExecError{type: $type, message: $message}';
}
}
enum ErrorType {
authentication,
localError,
missingEndpoint,
2022-11-17 16:04:14 +00:00
notFound,
2022-11-09 02:19:44 +00:00
parsingError,
}
extension ExecErrorExtension<T, E> on Result<T, E> {
Result<T, ExecError> execErrorCast() => mapError((error) => error is ExecError
? error
: ExecError(type: ErrorType.localError, message: error.toString()));
FutureResult<T, ExecError> execErrorCastAsync() async => execErrorCast();
}