@@ -66,17 +66,35 @@ class Request {
6666 }
6767
6868 Future <Response <String >> getTextResponseForUrl (String url) async {
69- final response = await _clashDio
70- .get <String >(
71- url,
72- options: Options (
73- responseType: ResponseType .plain,
74- sendTimeout: profileRequestTimeoutDuration,
75- receiveTimeout: profileRequestTimeoutDuration,
76- ),
77- )
78- .timeout (profileRequestTimeoutDuration);
79- return response;
69+ try {
70+ return await _clashDio
71+ .get <String >(
72+ url,
73+ options: Options (
74+ responseType: ResponseType .plain,
75+ sendTimeout: profileRequestTimeoutDuration,
76+ receiveTimeout: profileRequestTimeoutDuration,
77+ ),
78+ )
79+ .timeout (profileRequestTimeoutDuration);
80+ } catch (e) {
81+ commonPrint.log ('getTextResponseForUrl error ${e .toString ()}' );
82+ if (e is TimeoutException ) {
83+ throw appLocalizations.networkException;
84+ }
85+ if (e is DioException ) {
86+ if (e.type == DioExceptionType .unknown) {
87+ throw appLocalizations.unknownNetworkError;
88+ } else if (e.type == DioExceptionType .badResponse ||
89+ e.type == DioExceptionType .connectionTimeout ||
90+ e.type == DioExceptionType .sendTimeout ||
91+ e.type == DioExceptionType .receiveTimeout) {
92+ throw appLocalizations.networkException;
93+ }
94+ rethrow ;
95+ }
96+ throw appLocalizations.unknownNetworkError;
97+ }
8098 }
8199
82100 Future <MemoryImage ?> getImage (String url) async {
0 commit comments