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