send<T> method
Implementation
Future<Response> send<T>() async {
if (!showLogs) {
print("Welcome To Fore Astro Astrologer");
} else if (method == "POST") {
logger.w(
"New $method Request Send : -> $url ",
stackTrace: StackTrace.fromString("$method : $url"),
);
} else if (method == "GET") {
logger.i(
"New $method Request Send : -> $url ",
stackTrace: StackTrace.fromString("$method : $url"),
);
} else if (method == "DELETE") {
logger.w(
"New $method Request Send : -> $url ",
stackTrace: StackTrace.fromString("$method : $url"),
);
} else {
logger.f(
"New $method Request Send : -> $url ",
stackTrace: StackTrace.fromString("$method : $url"),
);
}
try {
SharedPreferences sharedPreferences =
await SharedPreferences.getInstance();
Response data = await dio.request<T>(
url,
cancelToken: cancelToken,
onReceiveProgress: onReceiveProgress,
onSendProgress: onSendProgress,
queryParameters: queryParameters,
data: body,
options: options ??
Options(method: method ?? ApiMethod.GET, headers: {
'Authorization': 'Bearer ${sharedPreferences.getString("token")}',
}),
);
if (showLogs) {
logger.t(data.data,
stackTrace: StackTrace.fromString("RESPONSE $method : $url"));
}
return data;
} on DioException catch (e) {
print(
"======================= $method Dio Error ========================");
logger.e(e.response?.data,
error: e.error, stackTrace: StackTrace.fromString("$method : $url"));
rethrow;
} catch (e) {
print(
"======================= $method Catch Error ========================");
logger.e(e, stackTrace: StackTrace.fromString("$method : $url"));
rethrow;
}
}