File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,13 +39,31 @@ export default function Home() {
3939 body : form ,
4040 } ) ;
4141
42- const payload = await response . json ( ) ;
42+ const rawText = await response . text ( ) ;
43+ let payload : unknown = rawText ;
44+ if ( rawText ) {
45+ try {
46+ payload = JSON . parse ( rawText ) ;
47+ } catch {
48+ payload = rawText ;
49+ }
50+ }
51+
4352 if ( ! response . ok ) {
44- setStatus ( payload ?. error ?? "Scan failed" ) ;
45- setResult ( null ) ;
46- } else {
47- setStatus ( "Scan complete" ) ;
53+ const message =
54+ typeof payload === "object" && payload !== null && "error" in payload
55+ ? String ( ( payload as { error ?: string } ) . error )
56+ : `Scan failed (${ response . status } )` ;
57+ setStatus ( message ) ;
58+ setResult ( rawText || null ) ;
59+ return ;
60+ }
61+
62+ setStatus ( "Scan complete" ) ;
63+ if ( payload && typeof payload === "object" ) {
4864 setResult ( JSON . stringify ( payload , null , 2 ) ) ;
65+ } else {
66+ setResult ( rawText || null ) ;
4967 }
5068 } catch ( error ) {
5169 setStatus ( "Failed to reach backend. Is it running on :7070?" ) ;
You can’t perform that action at this time.
0 commit comments