Action

PHOTO EMBED

Wed Jan 24 2024 16:58:19 GMT+0000 (Coordinated Universal Time)

Saved by @Timur #dart #flutter

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));
  }
}
content_copyCOPY

Action for impl repository