From 587749144b8a38fe020386461f7dcfc891fdef0a Mon Sep 17 00:00:00 2001 From: Potenz Date: Sat, 13 Dec 2025 02:21:57 +0530 Subject: [PATCH] fix - error showing issue --- .../insurance-status/ddma-buton-modal.tsx | 20 +++++++++---------- apps/Frontend/src/lib/queryClient.ts | 18 ++++++++++++++--- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/apps/Frontend/src/components/insurance-status/ddma-buton-modal.tsx b/apps/Frontend/src/components/insurance-status/ddma-buton-modal.tsx index 380c5eb..061f67d 100644 --- a/apps/Frontend/src/components/insurance-status/ddma-buton-modal.tsx +++ b/apps/Frontend/src/components/insurance-status/ddma-buton-modal.tsx @@ -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 || diff --git a/apps/Frontend/src/lib/queryClient.ts b/apps/Frontend/src/lib/queryClient.ts index bdb3d8f..987247e 100644 --- a/apps/Frontend/src/lib/queryClient.ts +++ b/apps/Frontend/src/lib/queryClient.ts @@ -15,13 +15,25 @@ async function throwIfResNotOk(res: Response) { // Try to parse the response as JSON for a more meaningful error message let message = `${res.status}: ${res.statusText}`; + try { - const errorBody = await res.json(); - if (errorBody?.message) { + const errorBody = await res.clone().json(); + + if (errorBody?.error) { + message = errorBody.error; + } else if (errorBody?.message) { message = errorBody.message; + } else if (errorBody?.detail) { + message = errorBody.detail; } } catch { - // ignore JSON parse errors, keep default message + // fallback to reading raw text so no error is lost + try { + const text = await res.clone().text(); + if (text?.trim()) { + message = text.trim(); + } + } catch {} } throw new Error(message);