add
This commit is contained in:
@@ -79,14 +79,24 @@ class _AddCountryPageState extends State<AddCountryPage> {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
_showDialog('错误', '服务器响应异常: ${response.statusCode}');
|
// 处理400错误时获取服务器返回的具体消息
|
||||||
|
String errorMessage = '服务器响应异常: ${response.statusCode}';
|
||||||
|
if (response.statusCode == 400 && response.data != null) {
|
||||||
|
errorMessage = response.data['message'] ?? errorMessage;
|
||||||
|
}
|
||||||
|
_showDialog('错误', errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
// 异常处理(保持不变)
|
// 异常处理(优化错误信息提取)
|
||||||
String errorMessage = '网络请求失败';
|
String errorMessage = '网络请求失败';
|
||||||
if (e.response != null) {
|
if (e.response != null) {
|
||||||
|
// 从响应数据中提取错误信息
|
||||||
|
if (e.response?.data != null && e.response?.data['message'] != null) {
|
||||||
|
errorMessage = e.response?.data['message'];
|
||||||
|
} else {
|
||||||
errorMessage = '请求失败: ${e.response?.statusCode}';
|
errorMessage = '请求失败: ${e.response?.statusCode}';
|
||||||
|
}
|
||||||
} else if (e.type == DioExceptionType.connectionTimeout) {
|
} else if (e.type == DioExceptionType.connectionTimeout) {
|
||||||
errorMessage = '连接超时,请检查网络';
|
errorMessage = '连接超时,请检查网络';
|
||||||
} else if (e.type == DioExceptionType.connectionError) {
|
} else if (e.type == DioExceptionType.connectionError) {
|
||||||
|
|||||||
Reference in New Issue
Block a user