createConnectivityInterceptor function
InterceptorsWrapper
createConnectivityInterceptor()
创建连通性拦截器(简化的工厂方法)
Implementation
InterceptorsWrapper createConnectivityInterceptor() {
return InterceptorsWrapper(
onRequest: (options, handler) async {
try {
final connectivity = await Connectivity().checkConnectivity();
if (connectivity == ConnectivityResult.none) {
return handler.reject(
DioException(
requestOptions: options,
type: DioExceptionType.connectionError,
error: '网络异常,请检查网络连接',
),
);
} else {
handler.next(options);
}
} catch (error) {
handler.next(options);
}
},
);
}