get method
Future<ApiServiceResponse>
get({
- required String endpoint,
- required Map<
String, dynamic> queryParameters, - CancelToken? cancelToken,
- bool logResponse = true,
get
Implementation
Future<ApiServiceResponse> get({
required String endpoint,
required Map<String, dynamic> queryParameters,
CancelToken? cancelToken,
bool logResponse = true,
}) async {
try {
LoggerService.logInfo(
'Endpoint: $endpoint',
);
LoggerService.logInfo('QueryParameters: $queryParameters');
final response = await _dio.get<dynamic>(
endpoint,
queryParameters: queryParameters,
cancelToken: cancelToken,
);
LoggerService.logInfo(
'Status code $endpoint: ${response.statusCode}',
);
if (response.statusCode == 200) {
return SuccessResponse(
data: response.data,
header: response.headers,
isRedirect: response.isRedirect,
);
}
LoggerService.logInfo(
'Status code $endpoint: ${response.statusCode}',
);
if (response.statusCode == 200) {
if (logResponse) {
LoggerService.logInfo('Response $endpoint: ${response.data}');
}
return SuccessResponse(
data: response.data,
header: response.headers,
isRedirect: response.isRedirect,
);
}
LoggerService.logError(
'Status not 200 $endpoint: ${response.data}',
);
return FailureResponse(
data: response.data,
header: response.headers,
isRedirect: response.isRedirect,
);
} on DioException catch (err) {
return FailureResponse(data: 'DioException Format err: $err');
} on FormatException catch (err) {
LoggerService.logError('Invalid Format $err');
return FailureResponse(data: 'Invalid Format');
} catch (e) {
LoggerService.logError('Error $endpoint: $e');
return FailureResponse(data: 'Invalid Error');
}
}