get<T> method
Future<Result<T> >
get<T>(
- String path, {
- Map<
String, dynamic> ? queryParameters, - FutureOr<
T> onSuccess(- dynamic data
- FutureOr<
T> onError(- dynamic data
- 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,
);
}
}