forked from baron/baron-sso
fix: handle json parse exceptions on 404/500 signup responses gracefully
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user