feat(ddma-eligibility) - fix1

This commit is contained in:
2025-12-13 01:46:52 +05:30
parent a7f939e26a
commit 52b0b6eb5c

View File

@@ -431,37 +431,21 @@ export function DdmaEligibilityButton({
let bodyText = ""; let bodyText = "";
try { try {
// Try to parse JSON (works when backend returns JSON body) result = await response.clone().json();
result = await response.json(); } catch {
} catch (jsonErr) {
// If JSON parsing fails, try to read raw text so we can show something meaningful
try { try {
bodyText = await response.text(); bodyText = await response.clone().text();
} catch (textErr) { } catch {}
bodyText = "";
}
} }
// Determine error message robustly
const backendError = const backendError =
// prefer explicit error field
result?.error || result?.error ||
// sometimes APIs return 'message' or 'detail'
result?.message || result?.message ||
result?.detail || result?.detail ||
// if JSON parse failed but bodyText contains something useful, use it (bodyText && bodyText.trim()) ||
(bodyText && bodyText.trim() ? bodyText.trim() : null); null;
if (!response.ok) { if (!response.ok) {
// Log server response for debugging
console.warn("DDMA start failed response:", {
status: response.status,
ok: response.ok,
result,
bodyText,
});
// Throw with the backend message if available, otherwise throw generic
throw new Error( throw new Error(
backendError || backendError ||
`DDMA selenium start failed (status ${response.status})` `DDMA selenium start failed (status ${response.status})`