修改生成路径的接口的返还数据结构判定语句
This commit is contained in:
@@ -27,8 +27,9 @@ class PathHttpDatasourceImpl implements PathHttpDatasource {
|
||||
print('响应体: ${response.body}');
|
||||
try {
|
||||
final decoded = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
if (decoded['code'] == 200) {
|
||||
final pathJson = decoded['path'];
|
||||
if (decoded['success'] == true) {
|
||||
final pathJson = decoded['data']?['path'];
|
||||
print('路径数据: $pathJson'); // 调试输出路径数据
|
||||
if (pathJson == null) {
|
||||
throw Exception('API returned null for "path"');
|
||||
}
|
||||
@@ -38,10 +39,12 @@ class PathHttpDatasourceImpl implements PathHttpDatasource {
|
||||
final List<dynamic> jsonData = pathJson;
|
||||
return jsonData.map((item) => DeviceAddPathPointModel.fromJson(item)).toList();
|
||||
} else {
|
||||
throw Exception('Failed to load path: ${response.statusCode}');
|
||||
final apiCode = decoded['code'] ?? -1;
|
||||
final msg = decoded['msg'] ?? '未知错误';
|
||||
throw Exception('API 错误 [$apiCode]: $msg');
|
||||
}
|
||||
} catch (e) {
|
||||
throw Exception('Network error: $e');
|
||||
throw Exception('Network error: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user