networkRequestHandler<T> function
Future<void>
networkRequestHandler<T>({
- required Future<
BaseResponse< apiCall(),T> > - dynamic onSuccess(
- T?
- dynamic onError()?,
Generic API request handler
Implementation
Future<void> networkRequestHandler<T>({
required Future<BaseResponse<T>> Function() apiCall,
Function(T?)? onSuccess,
Function(String)? onError,
}) async {
try {
final response = await apiCall();
if (response.success == Constant.successResCheckValue) {
onSuccess?.call(response.data);
} else {
onError?.call(response.message ?? "Unknown error occurred.");
}
} on DioException catch (dioError) {
// Handling network or API request errors
onError?.call(_getDioErrorMessage(dioError));
} catch (e) {
// Generic error fallback
onError?.call("Unexpected error: ${e.toString()}");
}
}