import 'dart:io'; import 'package:dartz/dartz.dart'; import '../api/api_exceptions.dart'; import '../entities/app_error.dart'; Future<Either<AppError, T>> action<T>({required Future<T> task}) async { try { final response = await task; return Right(response); } on SocketException { return const Left(AppError(appErrorType: AppErrorType.network)); } on UnauthorisedException { return const Left(AppError(appErrorType: AppErrorType.unauthorised)); } on ExceptionWithMessage catch (e) { return Left( AppError(appErrorType: AppErrorType.msgError, errorMessage: e.message)); } on Exception { return const Left(AppError(appErrorType: AppErrorType.api)); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter