2022-12-14 21:53:46 +00:00
|
|
|
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,
|
|
|
|
}
|
2022-12-14 21:53:46 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|