Skip to content

Commit 665c009

Browse files
committed
fix: add rsshub discover error boundary
Signed-off-by: Innei <[email protected]>
1 parent b1c5d84 commit 665c009

File tree

8 files changed

+61
-15
lines changed

8 files changed

+61
-15
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { FC } from "react"
2+
3+
import { attachOpenInEditor } from "~/lib/dev"
4+
5+
import type { AppErrorFallbackProps } from "../common/AppErrorBoundary"
6+
import { FeedbackIssue } from "../common/ErrorElement"
7+
import { parseError } from "./helper"
8+
9+
const RSSHubErrorFallback: FC<AppErrorFallbackProps> = (props) => {
10+
const { message, stack } = parseError(props.error)
11+
12+
return (
13+
<div className="flex flex-col items-center justify-center">
14+
<div className="m-auto max-w-prose text-center">
15+
<p className="center my-3 gap-2 font-bold">
16+
<i className="i-mgc-bug-cute-re text-red-500" />
17+
RSSHub has a temporary problem, please contact the our team.
18+
</p>
19+
<div className="text-lg">{message}</div>
20+
{import.meta.env.DEV && stack ? (
21+
<pre className="mt-4 max-h-48 cursor-text overflow-auto whitespace-pre-line rounded-md bg-red-50 p-4 text-left font-mono text-sm text-red-600">
22+
{attachOpenInEditor(stack)}
23+
</pre>
24+
) : null}
25+
26+
<FeedbackIssue message={message!} stack={stack} />
27+
</div>
28+
</div>
29+
)
30+
}
31+
export default RSSHubErrorFallback

apps/renderer/src/components/errors/enum.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ export enum ErrorComponentType {
55
// Feed
66
FeedFoundCanBeFollow = "FeedFoundCanBeFollow",
77
FeedNotFound = "FeedNotFound",
8+
// Section
9+
RSSHubDiscoverError = "RSSHubDiscoverError",
810
}

apps/renderer/src/components/errors/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const ErrorFallbackMap = {
99
() => import("./FeedFoundCanBeFollowErrorFallback"),
1010
),
1111
[ErrorComponentType.FeedNotFound]: lazy(() => import("./FeedNotFound")),
12+
[ErrorComponentType.RSSHubDiscoverError]: lazy(() => import("./RSSHubError")),
1213
}
1314

1415
export const getErrorFallback = (type: ErrorComponentType) => ErrorFallbackMap[type]

apps/renderer/src/modules/new-user-guide/guide-modal-content.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export function GuideModalContent({ onClose }: { onClose: () => void }) {
112112
{
113113
title: t.app("new_user_guide.step.shortcuts.title"),
114114
content: (
115-
<div className="w-[400px] space-y-2">
115+
<div className="space-y-2">
116116
<p>{t.app("new_user_guide.step.shortcuts.description1")}</p>
117117
<p>
118118
<Trans

apps/renderer/src/modules/new-user-guide/steps/behavior.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,22 @@ export function BehaviorGuide() {
4747
wrapperClassName="border rounded-lg p-3 has-[:checked]:bg-theme-accent has-[:checked]:text-white transition-colors"
4848
label={t("new_user_guide.step.behavior.unread_question.option1")}
4949
value="radical"
50+
className="hidden"
51+
labelClassName="pl-0"
5052
/>
5153
<Radio
5254
wrapperClassName="border rounded-lg p-3 has-[:checked]:bg-theme-accent has-[:checked]:text-white transition-colors"
5355
label={t("new_user_guide.step.behavior.unread_question.option2")}
5456
value="balanced"
57+
className="hidden"
58+
labelClassName="pl-0"
5559
/>
5660
<Radio
5761
wrapperClassName="border rounded-lg p-3 has-[:checked]:bg-theme-accent has-[:checked]:text-white transition-colors"
5862
label={t("new_user_guide.step.behavior.unread_question.option3")}
5963
value="conservative"
64+
className="hidden"
65+
labelClassName="pl-0"
6066
/>
6167
</RadioGroup>
6268
</div>

apps/renderer/src/modules/new-user-guide/steps/rsshub.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { ScrollArea } from "@follow/components/ui/scroll-area/index.js"
22

3+
import { AppErrorBoundary } from "~/components/common/AppErrorBoundary"
4+
import { ErrorComponentType } from "~/components/errors/enum"
35
import { useAuthQuery } from "~/hooks/common"
46
import { Recommendations } from "~/modules/discover/recommendations"
57
import { Queries } from "~/queries"
@@ -27,10 +29,12 @@ export function RSSHubGuide() {
2729
}
2830

2931
return (
30-
<ScrollArea.ScrollArea viewportClassName="h-[450px]">
31-
<div className="space-y-3">
32-
<Recommendations hideTitle className="grid-cols-4" />
33-
</div>
34-
</ScrollArea.ScrollArea>
32+
<AppErrorBoundary errorType={ErrorComponentType.RSSHubDiscoverError}>
33+
<ScrollArea.ScrollArea viewportClassName="h-[450px]">
34+
<div className="space-y-3">
35+
<Recommendations hideTitle className="grid-cols-4" />
36+
</div>
37+
</ScrollArea.ScrollArea>
38+
</AppErrorBoundary>
3539
)
3640
}

apps/renderer/src/pages/(main)/(layer)/(subview)/discover/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { useTranslation } from "react-i18next"
66
import { useSearchParams } from "react-router-dom"
77

88
import { useUserRole } from "~/atoms/user"
9+
import { AppErrorBoundary } from "~/components/common/AppErrorBoundary"
10+
import { ErrorComponentType } from "~/components/errors/enum"
911
import { useActivationModal } from "~/modules/activation"
1012
import { DiscoverForm } from "~/modules/discover/form"
1113
import { DiscoverImport } from "~/modules/discover/import"
@@ -114,7 +116,9 @@ export function Component() {
114116
</TabsContent>
115117
))}
116118
</Tabs>
117-
<Recommendations />
119+
<AppErrorBoundary errorType={ErrorComponentType.RSSHubDiscoverError}>
120+
<Recommendations />
121+
</AppErrorBoundary>
118122
</div>
119123
)
120124
}

packages/components/src/ui/radio-group/Radio.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ export const Radio: FC<
99
React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> & {
1010
label: ReactNode
1111
wrapperClassName?: string
12+
labelClassName?: string
1213
}
1314
> = (props) => {
14-
const { id, label, className, wrapperClassName, value, onChange, ...rest } = props
15+
const { id, label, className, wrapperClassName, labelClassName, value, onChange, ...rest } = props
1516
const { onChange: ctxOnChange } = useRadioContext() || {}
1617
const fallbackId = useId()
1718

@@ -22,7 +23,7 @@ export const Radio: FC<
2223
onChange?.(e)
2324
})
2425
return (
25-
<div className={cn("flex items-center", wrapperClassName)}>
26+
<label className={cn("flex items-center", wrapperClassName)} htmlFor={id ?? fallbackId}>
2627
<input
2728
{...rest}
2829
type="radio"
@@ -36,12 +37,9 @@ export const Radio: FC<
3637
onChange={handleChange}
3738
/>
3839

39-
<label
40-
className={cn(rest.disabled ? "text-theme-disabled" : "", "pl-2")}
41-
htmlFor={id ?? fallbackId}
42-
>
40+
<span className={cn(rest.disabled ? "text-theme-disabled" : "", "pl-2", labelClassName)}>
4341
{label}
44-
</label>
45-
</div>
42+
</span>
43+
</label>
4644
)
4745
}

0 commit comments

Comments
 (0)