Skip to content

Commit e251f8a

Browse files
xrgzsCopilot
andauthored
feat(File): Add ErrorBoundary to Previews (#561)
* fix(File): add ErrorBoundary to Previews * fix(url): throw Error directly Co-authored-by: Copilot <copilot@github.com> Signed-off-by: MadDogOwner <xiaoran@xrgzs.top>
1 parent 2d52742 commit e251f8a

2 files changed

Lines changed: 17 additions & 15 deletions

File tree

src/pages/home/file/File.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HStack, VStack } from "@hope-ui/solid"
2-
import { createMemo, Show, Suspense } from "solid-js"
2+
import { createMemo, ErrorBoundary, Show, Suspense } from "solid-js"
33
import { Dynamic } from "solid-js/web"
4-
import { FullLoading, SelectWrapper } from "~/components"
4+
import { Error, FullLoading, SelectWrapper } from "~/components"
55
import { objStore } from "~/store"
66
import { useRouter } from "~/hooks"
77
import { Download } from "../previews/download"
@@ -38,9 +38,11 @@ const File = () => {
3838
/>
3939
<OpenWith />
4040
</HStack>
41-
<Suspense fallback={<FullLoading />}>
42-
<Dynamic component={cur()?.component} />
43-
</Suspense>
41+
<ErrorBoundary fallback={(err) => <Error msg={String(err)} />}>
42+
<Suspense fallback={<FullLoading />}>
43+
<Dynamic component={cur()?.component} />
44+
</Suspense>
45+
</ErrorBoundary>
4446
</VStack>
4547
</Show>
4648
)

src/pages/home/previews/url.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ import { createMemo } from "solid-js"
99
export default function () {
1010
const [content] = useFetchText()
1111
const { copy } = useUtil()
12+
const t = useT()
1213
const url = createMemo(() => {
13-
try {
14-
const ini = content()?.content || ""
15-
const { text } = useParseText(ini)
16-
const config = recordKeysToLowerCase(parse(text() || ""))
17-
return config.internetshortcut?.url || "#"
18-
} catch (error) {
19-
console.error("Error parsing INI content:", error)
20-
return "#"
21-
}
14+
if (content.loading) return ""
15+
const ini = content()?.content
16+
if (!ini) throw new Error("No content")
17+
if (typeof ini === "string") throw new Error(ini)
18+
const { text } = useParseText(ini)
19+
const config = recordKeysToLowerCase(parse(text() || ""))
20+
const shortcutUrl = config.internetshortcut?.url
21+
if (!shortcutUrl) throw new Error("Invalid .url file: no URL found")
22+
return shortcutUrl
2223
})
23-
const t = useT()
2424
return (
2525
<MaybeLoading loading={content.loading}>
2626
<FileInfo>

0 commit comments

Comments
 (0)