/*
* error统一处理
*/
void formatError(Function errorCallBack, DioError e) {
if (e.type == DioErrorType.CONNECT_TIMEOUT) {
// It occurs when url is opened timeout.
errorCallBack("连接超时");
// showToast("连接超时");
} else if (e.type == DioErrorType.SEND_TIMEOUT) {
// It occurs when url is sent timeout.
errorCallBack("请求超时");
// showToast("请求超时");
} else if (e.type == DioErrorType.RECEIVE_TIMEOUT) {
//It occurs when receiving timeout
errorCallBack("响应超时");
// showToast("响应超时");
} else if (e.type == DioErrorType.RESPONSE) {
// When the server response, but with a incorrect status, such as 404, 503...
errorCallBack("响应异常");
// showToast("响应异常");
} else if (e.type == DioErrorType.CANCEL) {
// When the request is cancelled, dio will throw a error with this type.
errorCallBack("请求取消");
// showToast("请求取消");
} else {
//DEFAULT Default error type, Some other Error. In this case, you can read the DioError.error if it is not null.
errorCallBack("未知错误");
// showToast("未知错误");
}
}
网友评论