get<T> method

  1. @override
Future<Result<T>> get<T>(
  1. String path, {
  2. Map<String, dynamic>? queryParameters,
  3. FutureOr<T> onSuccess(
    1. dynamic data
    )?,
  4. FutureOr<T> onError(
    1. dynamic data
    )?,
  5. RestApiClientRequestOptions? options,
})
override

Implementation

@override
Future<Result<T>> get<T>(
  String path, {
  Map<String, dynamic>? queryParameters,
  FutureOr<T> Function(dynamic data)? onSuccess,
  FutureOr<T> Function(dynamic data)? onError,
  RestApiClientRequestOptions? options,
}) async {
  try {
    final response = await _dio.get(
      path,
      queryParameters: queryParameters,
      options: options?.toOptions(),
    );

    if (_options.cacheEnabled) {
      await cacheHandler.set(response);
    }

    return NetworkResult(
      response: response,
      data: await _resolveResult(response.data, onSuccess),
    );
  } on DioException catch (e) {
    await exceptionHandler.handle(e, silent: options?.silentException);

    return NetworkResult(
      response: e.response,
      errorData: await _resolveResult(e.response?.data, onError),
      exception: e,
      statusCode: e.response?.statusCode,
      statusMessage: e.response?.statusMessage,
    );
  }
}