call<T extends MdmObject> method

Future<Either<T, MdmEngineException>> call<T extends MdmObject>({
  1. required Future<T> request(
    1. ManageEngineClients clients
    ),
})

Implementation

Future<Either<T, MdmEngineException>> call<T extends MdmObject>({
  required Future<T> Function(
    ManageEngineClients clients,
  ) request,
}) async {
  try {
    final result = await request(clients);
    return Success(result);
  } on MdmEngineException catch (error, stackTrace) {
    log(error.toString());
    log(stackTrace.toString());
    return Failure(
      MdmEngineException(
        error: error.error,
        method: error.method,
        url: error.url,
        statusCode: error.statusCode,
        stackTrace: stackTrace,
      ),
    );
  } catch (error, stackTrace) {
    final exception = MdmEngineException(
      error: error,
      stackTrace: stackTrace,
    );

    log('An unknown error occured while processing the request. ${exception.toString()}');
    log(stackTrace.toString());
    return Failure(exception);
  }
}