Action

PHOTO EMBED

Fri Jan 19 2024 18:23:36 GMT+0000 (Coordinated Universal Time)

Saved by @Samuel1347 #flutter #dart

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