-
-
Notifications
You must be signed in to change notification settings - Fork 181
feat: add error handling and localization for key loading failures #365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,11 +52,13 @@ export function EditKeyForm({ keyData, user, onSuccess }: EditKeyFormProps) { | |
|
|
||
| // Load provider group suggestions | ||
| useEffect(() => { | ||
| if (user?.id) { | ||
| getAvailableProviderGroups(user.id).then(setProviderGroupSuggestions); | ||
| } else { | ||
| getAvailableProviderGroups().then(setProviderGroupSuggestions); | ||
| } | ||
| const loadGroups = user?.id | ||
| ? getAvailableProviderGroups(user.id) | ||
| : getAvailableProviderGroups(); | ||
|
|
||
| loadGroups.then(setProviderGroupSuggestions).catch((err) => { | ||
| console.error("[EditKeyForm] Failed to load provider groups:", err); | ||
| }); | ||
|
Comment on lines
+59
to
+61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error handling for loading provider groups only logs to the console. This provides no feedback to the user, who might be confused about why suggestions aren't appearing. It would be better to show a toast notification to inform the user about the failure. You can use a generic error message from your translation files, for example |
||
| }, [user?.id]); | ||
|
|
||
| const formatExpiresAt = (expiresAt: string) => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,7 +76,11 @@ export function UserForm({ user, onSuccess, currentUser }: UserFormProps) { | |
|
|
||
| // 加载供应商分组建议 | ||
| useEffect(() => { | ||
| getAvailableProviderGroups().then(setProviderGroupSuggestions); | ||
| getAvailableProviderGroups() | ||
| .then(setProviderGroupSuggestions) | ||
| .catch((err) => { | ||
| console.error("[UserForm] Failed to load provider groups:", err); | ||
| }); | ||
|
Comment on lines
+81
to
+83
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error handling for loading provider groups only logs to the console. This provides no feedback to the user, who might be confused about why suggestions aren't appearing. It would be better to show a toast notification to inform the user about the failure. You can use a generic error message from your translation files, for example |
||
| }, []); | ||
|
|
||
| const form = useZodForm({ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,9 +112,14 @@ export function UsageLogsFilters({ | |
|
|
||
| // 加载该用户的 keys | ||
| if (newUserId) { | ||
| const keysResult = await getKeys(newUserId); | ||
| if (keysResult.ok && keysResult.data) { | ||
| setKeys(keysResult.data); | ||
| try { | ||
| const keysResult = await getKeys(newUserId); | ||
| if (keysResult.ok && keysResult.data) { | ||
| setKeys(keysResult.data); | ||
| } | ||
|
Comment on lines
+117
to
+119
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation handles exceptions when calling |
||
| } catch (error) { | ||
| console.error("Failed to load keys:", error); | ||
| toast.error(t("logs.error.loadKeysFailed")); | ||
| } | ||
| } else { | ||
| setKeys([]); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error handling for loading provider groups only logs to the console. This provides no feedback to the user, who might be confused about why suggestions aren't appearing. It would be better to show a toast notification to inform the user about the failure. You can use a generic error message from your translation files, for example
dashboard.error.loadFailed.