1
0
forked from baron/baron-sso

fix: handle json parse exceptions on 404/500 signup responses gracefully

This commit is contained in:
2026-04-06 16:29:08 +09:00
parent c78604df06
commit 46db7ac026

View File

@@ -990,8 +990,17 @@ class AuthProxyService {
);
if (response.statusCode != 200) {
final error = jsonDecode(response.body)['error'] ?? 'Signup failed';
throw Exception(error);
String errorMessage = 'Signup failed';
try {
final decoded = jsonDecode(response.body);
if (decoded is Map<String, dynamic> && decoded.containsKey('error')) {
errorMessage = decoded['error'];
}
} catch (e) {
// Fallback if the body isn't valid JSON (e.g., an HTML error page)
errorMessage = 'Server error (${response.statusCode}): ${response.body.isNotEmpty ? response.body.substring(0, response.body.length > 100 ? 100 : response.body.length) : "Unknown error"}';
}
throw Exception(errorMessage);
}
}
}