Samad14 commited on
Commit
9fc8479
·
1 Parent(s): bac1801

fix: handle non-200 responses in domains, interactions, ramachandran, SS components

Browse files

Add res.ok checks and error state to DomainArchitecture, StringDBViewer,
RamachandranPlot, and SecondaryStructureViewer. Prevents 'can't access
property map of undefined' crash when API returns 404/502.

bioai-platform/frontend/src/components/domains/DomainArchitecture.tsx CHANGED
@@ -17,17 +17,21 @@ export function DomainArchitecture({ accession }: { accession: string }) {
17
  const [data, setData] = useState<DomainsResponse | null>(null);
18
  const [loading, setLoading] = useState(true);
19
  const [tooltip, setTooltip] = useState<{ domain: Domain; x: number; y: number } | null>(null);
 
20
 
21
  useEffect(() => {
22
  setLoading(true);
 
23
  fetch(`/api/backend/api/domains/${accession}`)
24
- .then(r => r.json())
25
  .then(setData)
 
26
  .finally(() => setLoading(false));
27
  }, [accession]);
28
 
29
  if (loading) return <div className="text-text-muted text-sm animate-pulse">Loading domain annotations&hellip;</div>;
30
- if (!data) return <div className="text-error text-sm">Failed to load domains.</div>;
 
31
 
32
  const { sequence_length: seqLen, domains } = data;
33
  const W = 700;
 
17
  const [data, setData] = useState<DomainsResponse | null>(null);
18
  const [loading, setLoading] = useState(true);
19
  const [tooltip, setTooltip] = useState<{ domain: Domain; x: number; y: number } | null>(null);
20
+ const [error, setError] = useState<string | null>(null);
21
 
22
  useEffect(() => {
23
  setLoading(true);
24
+ setError(null);
25
  fetch(`/api/backend/api/domains/${accession}`)
26
+ .then(r => { if (!r.ok) throw new Error(`InterPro returned ${r.status}`); return r.json(); })
27
  .then(setData)
28
+ .catch(e => setError(e.message))
29
  .finally(() => setLoading(false));
30
  }, [accession]);
31
 
32
  if (loading) return <div className="text-text-muted text-sm animate-pulse">Loading domain annotations&hellip;</div>;
33
+ if (error) return <div className="text-error text-sm">{error}</div>;
34
+ if (!data) return <div className="text-error text-sm">No domain data returned.</div>;
35
 
36
  const { sequence_length: seqLen, domains } = data;
37
  const W = 700;
bioai-platform/frontend/src/components/interactions/StringDBViewer.tsx CHANGED
@@ -13,16 +13,21 @@ type Interaction = {
13
  export function StringDBViewer({ geneName }: { geneName: string }) {
14
  const [data, setData] = useState<{ interactions: Interaction[] } | null>(null);
15
  const [loading, setLoading] = useState(true);
 
16
  const svgRef = useRef<SVGSVGElement>(null);
17
 
18
  useEffect(() => {
 
 
19
  fetch(`/api/backend/api/interactions/${encodeURIComponent(geneName)}?limit=12`)
20
- .then(r => r.json())
21
  .then(setData)
 
22
  .finally(() => setLoading(false));
23
  }, [geneName]);
24
 
25
  if (loading) return <div className="text-text-muted text-sm animate-pulse">Fetching STRING-DB interactions&hellip;</div>;
 
26
  if (!data?.interactions?.length) return <div className="text-text-muted text-sm">No interactions found.</div>;
27
 
28
  const { interactions } = data;
 
13
  export function StringDBViewer({ geneName }: { geneName: string }) {
14
  const [data, setData] = useState<{ interactions: Interaction[] } | null>(null);
15
  const [loading, setLoading] = useState(true);
16
+ const [error, setError] = useState<string | null>(null);
17
  const svgRef = useRef<SVGSVGElement>(null);
18
 
19
  useEffect(() => {
20
+ setLoading(true);
21
+ setError(null);
22
  fetch(`/api/backend/api/interactions/${encodeURIComponent(geneName)}?limit=12`)
23
+ .then(r => { if (!r.ok) throw new Error(`STRING-DB returned ${r.status}`); return r.json(); })
24
  .then(setData)
25
+ .catch(e => setError(e.message))
26
  .finally(() => setLoading(false));
27
  }, [geneName]);
28
 
29
  if (loading) return <div className="text-text-muted text-sm animate-pulse">Fetching STRING-DB interactions&hellip;</div>;
30
+ if (error) return <div className="text-error text-sm">{error}</div>;
31
  if (!data?.interactions?.length) return <div className="text-text-muted text-sm">No interactions found.</div>;
32
 
33
  const { interactions } = data;
bioai-platform/frontend/src/components/structure/RamachandranPlot.tsx CHANGED
@@ -14,15 +14,20 @@ export function RamachandranPlot({ pdbId, chain = "A" }: { pdbId: string; chain?
14
  const [points, setPoints] = useState<RPoint[]>([]);
15
  const [loading, setLoading] = useState(true);
16
  const [hovered, setHovered] = useState<RPoint | null>(null);
 
17
 
18
  useEffect(() => {
 
 
19
  fetch(`/api/backend/api/structure_analysis/ramachandran/${pdbId}?chain=${chain}`)
20
- .then(r => r.json())
21
  .then(setPoints)
 
22
  .finally(() => setLoading(false));
23
  }, [pdbId, chain]);
24
 
25
  if (loading) return <div className="text-text-muted text-sm animate-pulse">Calculating &phi;/&psi; angles&hellip;</div>;
 
26
 
27
  const W = 400, H = 400, PAD = 40;
28
  const toX = (phi: number) => PAD + ((phi + 180) / 360) * (W - PAD * 2);
 
14
  const [points, setPoints] = useState<RPoint[]>([]);
15
  const [loading, setLoading] = useState(true);
16
  const [hovered, setHovered] = useState<RPoint | null>(null);
17
+ const [error, setError] = useState<string | null>(null);
18
 
19
  useEffect(() => {
20
+ setLoading(true);
21
+ setError(null);
22
  fetch(`/api/backend/api/structure_analysis/ramachandran/${pdbId}?chain=${chain}`)
23
+ .then(r => { if (!r.ok) throw new Error(`Failed: ${r.status}`); return r.json(); })
24
  .then(setPoints)
25
+ .catch(e => setError(e.message))
26
  .finally(() => setLoading(false));
27
  }, [pdbId, chain]);
28
 
29
  if (loading) return <div className="text-text-muted text-sm animate-pulse">Calculating &phi;/&psi; angles&hellip;</div>;
30
+ if (error) return <div className="text-error text-sm">{error}</div>;
31
 
32
  const W = 400, H = 400, PAD = 40;
33
  const toX = (phi: number) => PAD + ((phi + 180) / 360) * (W - PAD * 2);
bioai-platform/frontend/src/components/structure/SecondaryStructure.tsx CHANGED
@@ -9,15 +9,20 @@ const SS_LABEL: Record<string, string> = { H: "&alpha;-Helix", E: "&beta;-Sheet"
9
  export function SecondaryStructureViewer({ identifier }: { identifier: string }) {
10
  const [data, setData] = useState<{ method: string; residues: SSResidue[] } | null>(null);
11
  const [loading, setLoading] = useState(true);
 
12
 
13
  useEffect(() => {
 
 
14
  fetch(`/api/backend/api/structure_analysis/secondary_structure/${identifier}`)
15
- .then(r => r.json())
16
  .then(setData)
 
17
  .finally(() => setLoading(false));
18
  }, [identifier]);
19
 
20
  if (loading) return <div className="text-text-muted text-sm animate-pulse">Predicting secondary structure&hellip;</div>;
 
21
  if (!data) return <div className="text-error text-sm">Failed to load.</div>;
22
 
23
  const { residues, method } = data;
 
9
  export function SecondaryStructureViewer({ identifier }: { identifier: string }) {
10
  const [data, setData] = useState<{ method: string; residues: SSResidue[] } | null>(null);
11
  const [loading, setLoading] = useState(true);
12
+ const [error, setError] = useState<string | null>(null);
13
 
14
  useEffect(() => {
15
+ setLoading(true);
16
+ setError(null);
17
  fetch(`/api/backend/api/structure_analysis/secondary_structure/${identifier}`)
18
+ .then(r => { if (!r.ok) throw new Error(`Failed: ${r.status}`); return r.json(); })
19
  .then(setData)
20
+ .catch(e => setError(e.message))
21
  .finally(() => setLoading(false));
22
  }, [identifier]);
23
 
24
  if (loading) return <div className="text-text-muted text-sm animate-pulse">Predicting secondary structure&hellip;</div>;
25
+ if (error) return <div className="text-error text-sm">{error}</div>;
26
  if (!data) return <div className="text-error text-sm">Failed to load.</div>;
27
 
28
  const { residues, method } = data;