From 9e18ed4b8c55e9a79441b9e267973ffeaad2c096 Mon Sep 17 00:00:00 2001 From: Misaka_Company Date: Mon, 11 May 2026 12:47:21 +0800 Subject: [PATCH] feat: handle 400 status code with unified error format Co-Authored-By: Claude Opus 4.6 --- lib/services/api_service.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/services/api_service.dart b/lib/services/api_service.dart index ebf8bf6..a13ca0a 100644 --- a/lib/services/api_service.dart +++ b/lib/services/api_service.dart @@ -54,12 +54,16 @@ class ApiService { switch (response.statusCode) { case 200: return RegistrationResult.ok(); + case 400: + final body = jsonDecode(response.body) as Map; + final msg = body['message']?.toString() ?? '请求参数错误'; + return RegistrationResult.error(msg); case 409: final body = jsonDecode(response.body) as Map; return RegistrationResult.duplicate(body); default: final body = jsonDecode(response.body) as Map; - final msg = body['error'] ?? body['message'] ?? 'Unknown error (${response.statusCode})'; + final msg = body['message'] ?? body['error'] ?? 'Unknown error (${response.statusCode})'; return RegistrationResult.error(msg.toString()); } } catch (e) {