getDocumentData<T> method
Future<T>
getDocumentData<T>({
- required String endpoint,
- JSON? queryParams,
- CancelToken? cancelToken,
- CachePolicy? cachePolicy,
- int? cacheAgeDays,
- bool requiresAuthToken = true,
- required T converter(
- JSON response
override
Implementation
@override
Future<T> getDocumentData<T>({
required String endpoint,
JSON? queryParams,
CancelToken? cancelToken,
CachePolicy? cachePolicy,
int? cacheAgeDays,
bool requiresAuthToken = true,
required T Function(JSON response) converter,
}) async {
JSON body;
try {
final ResponseModel<JSON> data = await _dioService.get<JSON>(
endpoint: endpoint,
queryParams: queryParams,
cacheOptions: _dioService.globalCacheOptions?.copyWith(
policy: cachePolicy,
maxStale: cacheAgeDays != null
? Nullable(Duration(days: cacheAgeDays))
: null,
),
options: Options(
extra: <String, Object?>{
'requiresAuthToken': requiresAuthToken,
},
),
cancelToken: cancelToken,
);
body = data.body;
} on Exception catch (ex) {
throw CustomException.fromDioException(ex);
}
try {
return converter(body);
} on Exception catch (ex) {
throw CustomException.fromParsingException(ex);
}
}