Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/api/scripts/rotate-abha-secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ async function main() {
encryption_iv: iv,
encryption_salt: salt,
});
} catch (err: any) {
logger.error(`Failed to rotate secret for user ${record.user_id}: ${err.message}`);
} catch (err: unknown) {
logger.error(`Failed to rotate secret for user ${record.user_id}: ${err instanceof Error ? err.message : String(err)}`);
}
}

Expand Down
11 changes: 5 additions & 6 deletions apps/api/src/routes/abha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,9 @@ router.get(

const result = await getAbhaStatus(userId);
res.status(200).json(result);
} catch (error) {
res.status(500).json({
error: error instanceof Error ? error.message : "Failed to check ABHA status",
});
} catch (error: unknown) {
console.error("ABHA linking error:", error);
res.status(500).json({ error: error instanceof Error ? error.message : "Failed to link ABHA address" });
}
}
);
Expand Down Expand Up @@ -294,9 +293,9 @@ router.get(

const metricsResult = await downloadHealthRecords(userId);
res.status(200).json(metricsResult);
} catch (error: any) {
} catch (error: unknown) {
res.status(500).json({
error: error.message || "Records processing engine encountered an error",
error: error instanceof Error ? error.message : "Records processing engine encountered an error",
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/routes/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ router.post(
}

res.status(200).json(resultData);
} catch (mlError: any) {
} catch (mlError: unknown) {
clearTimeout(timeoutId);
logger.error(`Failed to connect or fetch from ML Service: ${mlError.message}`);
logger.error("ML service failed, falling back to basic matching", { error: mlError instanceof Error ? mlError.message : String(mlError) });
res.status(502).json({ error: "ML service comparison failed or timed out." });
}
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions apps/api/src/routes/eligibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ router.post("/", eligibilityLimiter, async (req: Request, res: Response): Promis
});
res.status(200).json({ eligible_schemes });
return;
} catch (err: any) {
} catch (err: unknown) {
logger.error("Error calling PM-JAY eligibility service", {
error: err.message || String(err),
name: err.name,
error: err instanceof Error ? err.message : String(err),
name: err instanceof Error ? err.name : "Unknown",
});

if (err instanceof PmjayAuthError) {
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/routes/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ router.get(
pharmacies = Array.isArray(rpcData)
? (rpcData as PharmacyRpcResult[]).map(formatNearbyPharmacy)
: [];
} catch (err: any) {
} catch (err: unknown) {
logger.warn({
message: "get_nearest_pharmacies RPC failed, falling back to db query",
error: err,
Expand Down Expand Up @@ -219,7 +219,7 @@ router.get(
if (rpcError) throw rpcError;

ashaWorkers = Array.isArray(rpcData) ? rpcData : [];
} catch (err: any) {
} catch (err: unknown) {
logger.warn({
message: "get_nearest_asha_workers RPC failed, falling back to db query",
error: err,
Expand Down
20 changes: 10 additions & 10 deletions apps/api/src/routes/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,9 @@ router.get("/status", limiter, optionalAuth, async (req: AuthenticatedRequest, r
} else {
subscriber = data;
}
} catch (dbError: any) {
} catch (dbError: unknown) {
dbFailed = true;
const msg = dbError?.message || String(dbError);
const msg = dbError instanceof Error ? dbError.message : String(dbError);
if (
msg.includes("fetch failed") ||
msg.includes("refused") ||
Expand Down Expand Up @@ -467,9 +467,9 @@ router.post(
} else {
existing = data;
}
} catch (dbError: any) {
} catch (dbError: unknown) {
dbFailed = true;
const msg = dbError?.message || String(dbError);
const msg = dbError instanceof Error ? dbError.message : String(dbError);
if (
msg.includes("fetch failed") ||
msg.includes("refused") ||
Expand Down Expand Up @@ -706,9 +706,9 @@ router.post(
} else {
subscriber = data;
}
} catch (dbError: any) {
} catch (dbError: unknown) {
dbFailed = true;
const msg = dbError?.message || String(dbError);
const msg = dbError instanceof Error ? dbError.message : String(dbError);
if (
msg.includes("fetch failed") ||
msg.includes("refused") ||
Expand Down Expand Up @@ -991,9 +991,9 @@ router.patch(
} else {
data = dbData;
}
} catch (dbError: any) {
} catch (dbError: unknown) {
dbFailed = true;
const msg = dbError?.message || String(dbError);
const msg = dbError instanceof Error ? dbError.message : String(dbError);
if (
msg.includes("fetch failed") ||
msg.includes("refused") ||
Expand Down Expand Up @@ -1074,9 +1074,9 @@ router.delete("/phone", limiter, optionalAuth, async (req: AuthenticatedRequest,
} else {
data = dbData;
}
} catch (dbError: any) {
} catch (dbError: unknown) {
dbFailed = true;
const msg = dbError?.message || String(dbError);
const msg = dbError instanceof Error ? dbError.message : String(dbError);
if (
msg.includes("fetch failed") ||
msg.includes("refused") ||
Expand Down
41 changes: 23 additions & 18 deletions apps/api/src/routes/pharmacies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,10 @@ router.post(

const pharmacy = await pharmacyService.registerPharmacy(parsed.data, req.user.id);
res.status(201).json({ pharmacy });
} catch (err: any) {
if (err.status) {
res.status(err.status).json({ error: err.message });
} catch (err: unknown) {
const status = err && typeof err === 'object' && 'status' in err ? (err as any).status : null;
if (status) {
res.status(status).json({ error: err instanceof Error ? err.message : String(err) });
return;
}
next(err);
Expand Down Expand Up @@ -601,12 +602,13 @@ router.get(

const result = await pharmacyService.searchByMedicine(rawQuery);
res.json(result);
} catch (err: any) {
if (err.status) {
res.status(err.status).json({ error: err.message });
} catch (err: unknown) {
const status = err && typeof err === 'object' && 'status' in err ? (err as any).status : null;
if (status) {
res.status(status).json({ error: err instanceof Error ? err.message : String(err) });
return;
}
logger.error("Pharmacy medicine search failed", { error: err.message });
logger.error("Pharmacy medicine search failed", { error: err instanceof Error ? err.message : String(err) });
res.status(500).json({ error: "Database query failed" });
}
}
Expand Down Expand Up @@ -979,7 +981,7 @@ router.post(
);
res.end();
}
} catch (err: any) {
} catch (err: unknown) {
const message = err instanceof Error ? err.message : "Unknown error";
logger.error(`Exception in bulk operations handler: ${message}`);
if (!res.headersSent) {
Expand Down Expand Up @@ -1018,9 +1020,10 @@ router.put(
req.body
);
res.status(200).json({ pharmacy });
} catch (err: any) {
if (err.status) {
res.status(err.status).json({ error: err.message });
} catch (err: unknown) {
const status = err && typeof err === 'object' && 'status' in err ? (err as any).status : null;
if (status) {
res.status(status).json({ error: err instanceof Error ? err.message : String(err) });
return;
}
next(err);
Expand All @@ -1045,9 +1048,10 @@ router.delete(
const pharmacyId = String(req.params.id);
await pharmacyService.deletePharmacy(pharmacyId, req.user!.id, req.user!.role);
res.status(200).json({ message: "Pharmacy deleted successfully" });
} catch (err: any) {
if (err.status) {
res.status(err.status).json({ error: err.message });
} catch (err: unknown) {
const status = err && typeof err === 'object' && 'status' in err ? (err as any).status : null;
if (status) {
res.status(status).json({ error: err instanceof Error ? err.message : String(err) });
return;
}
next(err);
Expand Down Expand Up @@ -1079,12 +1083,13 @@ router.post(
fileContent
);
res.status(200).json(result);
} catch (err: any) {
if (err.status) {
res.status(err.status).json({ error: err.message });
} catch (err: unknown) {
const status = err && typeof err === 'object' && 'status' in err ? (err as any).status : null;
if (status) {
res.status(status).json({ error: err instanceof Error ? err.message : String(err) });
return;
}
logger.error(`Exception in specific pharmacy upload handler: ${err.message}`);
logger.error(`Exception in specific pharmacy upload handler: ${err instanceof Error ? err.message : String(err)}`);
next(err);
}
}
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/services/governmentEligibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ export async function fetchPmjayEligibility(
how_to_apply: s.how_to_apply,
link: s.link,
}));
} catch (err: any) {
} catch (err: unknown) {
logger.error("Error evaluating eligibility: ", err);
const errName = err?.name;
const errName = err instanceof Error ? err.name : null;
if (
err instanceof PmjayAuthError ||
errName === "PmjayAuthError" ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,14 @@ export default function BulkUploadPage() {
errors: data.errors,
});
}
} catch (parseErr: any) {
if (
parseErr.message !== "Unexpected end of JSON input" &&
!parseErr.message.includes("JSON")
) {
throw parseErr;
}
} catch (parseErr: unknown) {
throw parseErr;
}
}
}
}
} catch (err: any) {
setApiError(err.message || "An unexpected error occurred.");
} catch (err: unknown) {
setApiError(err instanceof Error ? err.message : "An unexpected error occurred.");
} finally {
setIsLoading(false);
setProgressStats(null);
Expand Down
4 changes: 2 additions & 2 deletions apps/web/app/[locale]/admin/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ export default function AdminDashboard() {
keys!
</>
);
} catch (err: any) {
} catch (err: unknown) {
notify(
<>
<XCircle className="mr-1 inline h-4 w-4" />{" "}
{err.message || "Cache flush failed"}
{err instanceof Error ? err.message : "Cache flush failed"}
</>,
false
);
Expand Down
16 changes: 8 additions & 8 deletions apps/web/app/[locale]/admin/synonyms/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@

if (error) throw error;
setSynonyms(data as OcrSynonym[]);
} catch (err: any) {
setError(err.message || t("fetchError"));
} catch (err: unknown) {
setError(err instanceof Error ? err.message : t("fetchError"));
} finally {
setLoading(false);
}
Expand Down Expand Up @@ -136,8 +136,8 @@
setNormalizedTerm("");
await fetchSynonyms();
await invalidateCache();
} catch (err: any) {
setError(err.message || t("addError"));
} catch (err: unknown) {
setError(err instanceof Error ? err.message : t("addError"));
} finally {
setActionLoading(null);
}
Expand All @@ -154,8 +154,8 @@

await fetchSynonyms();
await invalidateCache();
} catch (err: any) {
setError(err.message || t("deleteError"));
} catch (err: unknown) {
setError(err instanceof Error ? err.message : t("deleteError"));
} finally {
setActionLoading(null);
}
Expand All @@ -165,7 +165,7 @@
fetchSynonyms();
}, []);

const handleFileUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {

Check failure on line 168 in apps/web/app/[locale]/admin/synonyms/page.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=RatLoopz_sahidawa-india&issues=AZ_c-TRY6Oaq1Hsd4tqF&open=AZ_c-TRY6Oaq1Hsd4tqF&pullRequest=4212
const file = e.target.files?.[0];
if (!file) return;

Expand Down Expand Up @@ -220,8 +220,8 @@
await fetchSynonyms();
await invalidateCache();
toast.success(t("uploadSuccess", { count: payload.length }));
} catch (err: any) {
setError(err.message || t("uploadError"));
} catch (err: unknown) {
setError(err instanceof Error ? err.message : t("uploadError"));
if (fileInputRef.current) fileInputRef.current.value = "";
} finally {
setActionLoading(null);
Expand Down
4 changes: 2 additions & 2 deletions apps/web/app/[locale]/calculator/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ async function searchMedicines(query: string): Promise<Medicine[]> {
composition: row.composition,
cdsco_approval_status: row.cdsco_approval_status || "approved",
}));
} catch (error: any) {
console.error(error.message || error);
} catch (error: unknown) {
console.error(error instanceof Error ? error.message : error);
return [];
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/[locale]/components/Chatbot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export default function Chatbot() {
msg.id === typingMessage.id ? { id: msg.id, text: finalText, isBot: true } : msg
);
});
} catch (error: any) {
} catch (error: unknown) {
if (isAbortError(error)) return;

console.error("Chatbot API Error:", error);
Expand Down
4 changes: 2 additions & 2 deletions apps/web/app/[locale]/interaction-checker/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ export default function InteractionCheckerPage() {
setInteractions(sorted);
setIsOfflineResult(response.verified === false);
setHasChecked(true);
} catch (err: any) {
setError(err.message || t("errorMessage"));
} catch (err: unknown) {
setError(err instanceof Error ? err.message : t("errorMessage"));
} finally {
setIsLoading(false);
}
Expand Down
4 changes: 2 additions & 2 deletions apps/web/app/[locale]/scan/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ export default function ScanPage() {

try {
await handleVerify(scannedText);
} catch (error: any) {
setApiError(error.message || "Failed to verify medicine with CDSCO.");
} catch (error: unknown) {
setApiError(error instanceof Error ? error.message : "Failed to verify medicine with CDSCO.");
} finally {
setIsVerifying(false);
}
Expand Down
6 changes: 3 additions & 3 deletions apps/web/hooks/useAshaDashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export function useAshaDashboard() {

setStats(statsData);
setLeaderboard(leaderboardData.leaderboard);
} catch (err: any) {
setError(err.message || "An error occurred");
} catch (err: unknown) {
setError(err instanceof Error ? err.message : "An error occurred");
} finally {
setLoading(false);
}
Expand Down Expand Up @@ -66,7 +66,7 @@ export function useAshaDashboard() {
setLeaderboard(leaderboardData.leaderboard);

return data;
} catch (err: any) {
} catch (err: unknown) {
console.error(err);
throw err;
}
Expand Down
4 changes: 2 additions & 2 deletions apps/web/hooks/useLASAChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export function useLASAChecker() {
try {
const result = await checkLasaConflicts(query, controller.signal);
setData(result);
} catch (err: any) {
if (err.name === "AbortError") {
} catch (err: unknown) {
if (err instanceof Error && err.name === "AbortError") {
return;
}
console.error("useLASAChecker error:", err);
Expand Down
Loading
Loading