fix - error showing issue

This commit is contained in:
2025-12-13 02:21:57 +05:30
parent d6ab6a0b2b
commit 587749144b
2 changed files with 25 additions and 13 deletions

View File

@@ -428,23 +428,23 @@ export function DdmaEligibilityButton({
// If apiRequest threw, we would have caught above; but just in case it returns.
let result: any = null;
let bodyText = "";
let backendError: string | null = null;
try {
// attempt JSON first
result = await response.clone().json();
backendError =
result?.error || result?.message || result?.detail || null;
} catch {
// fallback to text response
try {
bodyText = await response.clone().text();
} catch {}
const text = await response.clone().text();
backendError = text?.trim() || null;
} catch {
backendError = null;
}
}
const backendError =
result?.error ||
result?.message ||
result?.detail ||
(bodyText && bodyText.trim()) ||
null;
if (!response.ok) {
throw new Error(
backendError ||