New Issue Checklist
- [x] I have searched for a similar issue in the project and found none
Issue Info
| Info | Value | |
| ------------------------------ | ----------------------------------------------------- | ---- |
| Platform Name | e.g. flutter / windows10/ android | |
| Platform Version | e.g. 1.22.4 / 10 / 9.0 | |
| Dio Version | e.g. 3.0.10 | |
| Visual Studio Code Version | e.g. 1.52.1 | |
| Repro rate | e.g. all the time (100%) / sometimes x% / only once | |
Issue Description and Steps
我使用leancloud的SDK,当对方服务器返回400错误的时候,vsc 就会跳到这个页面:
dio.dart 第966行
} catch (e) {
throw assureDioError(e, options);
}
并有红色提示:
Exception has occurred.
DioError (DioError [DioErrorType.RESPONSE]: Http status error [400])
于是我跟踪到此SDK的post动作,输出一些发送的数据与参数:
SDK 的文件 lc_http_client.dart , line70:
try {
print('=====1.The params to post:====={');
print(path);
print(options);
print(data);
print(queryParams);
print('=====1.The params to post:=====}');
Response response = await _dio.post(path,
options: options, data: data, queryParameters: queryParams);
return response.data;
} on DioError catch (e) {
print('=====2.Here catch DioError:====={');
print(e);
print('=====2.Here catch DioError:=====}');
_handleError(e); //此函数可以在这里点击查看 [ _handleError(e);](https://github.com/leancloud/Storage-SDK-Flutter/blob/985f9ad91e3b1d5824fd3340c68d6010a6c606e3/lib/internal/http/lc_http_client.dart)
}
我也附上我本身的业务逻辑的代码:
try {
developer.log('======Begin :=======');
await LCSMSClient.requestSMSCode(_phoneNumber);
}on DioError catch (e){
developer.log('======DioError catch=======');
} on LCException catch (e) {
developer.log('======LCException catch=======');
developer.log(e.message);
} catch (e) {
developer.log('======catch=======');
}
输出如下:
[log] ======Begin :=======
I/flutter ( 1793): =====1.The params to post:====={
I/flutter ( 1793): requestSmsCode
I/flutter ( 1793): Instance of 'Options'
I/flutter ( 1793): {"mobilePhoneNumber":"+8625786"}
I/flutter ( 1793): null
I/flutter ( 1793): =====1.The params to post:=====}
I/flutter ( 1793): =====2.Here catch DioError:====={
I/flutter ( 1793): DioError [DioErrorType.RESPONSE]: Http status error [400]
I/flutter ( 1793): =====2.Here catch DioError:=====}
[log] ======LCException catch=======
[log] 无效的手机号码。
问题:看输出,dio.post执行之后是可以catch到DioError的,但是为什么VSC编辑器每次都会跳转到
throw assureDioError(e, options);
并有红色提示呢?
即使我改为如下,不用on DioError或改为catchError,还是会跳转到throw assureDioError(e, options);并有红色提示。
try {
developer.log('======Begin :=======');
await LCSMSClient.requestSMSCode(_phoneNumber).catchError(( /DioError/ e) {
developer.log('======I am catchError=======');
});
}catch (e) {
developer.log('======catch=======');
}
输出:
V/AudioManager( 7109): querySoundEffectsEnabled...
[log] ======Begin :=======
[log] ======I am catchError=======
这里明显可以catch到,但为什么还会在throw assureDioError(e, options);里面抛出来呢?求大侠指导!
(已在github提出问题,希望尽快得到答复,谢谢:https://github.com/leancloud/Storage-SDK-Flutter/issues/98)