-
Notifications
You must be signed in to change notification settings - Fork 0
Standardize server action error handling with ActionResult type #29
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
base: v2
Are you sure you want to change the base?
Conversation
Co-authored-by: MaxtuneLee <[email protected]>
Co-authored-by: MaxtuneLee <[email protected]>
Co-authored-by: MaxtuneLee <[email protected]>
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.
Pull Request Overview
This PR standardizes error handling across server actions by replacing throw new Error() with a consistent ActionResult<T> return type. This improves type safety and ensures all errors are explicitly handled rather than relying on exception propagation.
- Introduces
ActionResult<T>type for standardized success/error responses - Refactors 5 server action files to return
ActionResultinstead of throwing errors - Updates 4 client components and 2 API routes to handle the new response format
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/types/action.ts | Defines the new ActionResult<T> discriminated union type |
| src/action/user-flow/register.ts | Wraps transaction in try-catch, returns ActionResult |
| src/action/user/auth.ts | Converts loginFromX and loginFromTest to return ActionResult |
| src/action/user/userInfo.ts | Adds try-catch to editBasicInfoByUid, returns ActionResult |
| src/action/user/link.ts | Converts get_user_access_token and bindingLinkAccount to return ActionResult |
| src/action/user/feishu.ts | Wraps get_user_access_token in try-catch, returns ActionResult |
| src/components/userFlow/submitRegister.tsx | Handles ActionResult from register action |
| src/components/testLogin.tsx | Handles ActionResult from loginFromTest action |
| src/components/userInfo/basic.tsx | Converts error to exception for toast.promise compatibility |
| src/components/manage/editUserInfoDialog.tsx | Checks result and displays appropriate toast message |
| src/app/api/auth/link/route.ts | Validates ActionResult responses and returns appropriate errors |
| src/app/api/auth/feishu/route.ts | Validates ActionResult responses and returns appropriate errors |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
@copilot resolve the suggestions above |
…remove redundant null checks Co-authored-by: MaxtuneLee <[email protected]>
All suggestions have been addressed in commit 70ae78d:
Additionally, I improved the |
✅ COMPLETED: Standardize Server Action Error Handling
Successfully unified server action error handling to return a standard format instead of using
throw new Error().📋 Summary of Changes:
Created Standard Result Type:
src/types/action.tswith improvedActionResult<T>typedataexists whensuccessis true (non-optional)Refactored Server Actions (5 files):
src/action/user-flow/register.ts- Wrapped in try-catch, returns ActionResultsrc/action/user/auth.ts- loginFromX and loginFromTest now return ActionResultsrc/action/user/userInfo.ts- Both functions wrapped in try-catch, return ActionResultsrc/action/user/link.ts- get_user_access_token and bindingLinkAccount return ActionResultsrc/action/user/feishu.ts- get_user_access_token returns ActionResultUpdated Client Components (4 files):
src/components/userFlow/submitRegister.tsx- Handles ActionResult from registersrc/components/testLogin.tsx- Handles ActionResult from loginFromTestsrc/components/userInfo/basic.tsx- Handles ActionResult from editBasicInfosrc/components/manage/editUserInfoDialog.tsx- Handles ActionResult from editBasicInfoByUidUpdated API Routes (2 files):
src/app/api/auth/feishu/route.ts- Removed redundant null check (type-safe)src/app/api/auth/link/route.ts- Removed redundant null check (type-safe)🎯 Benefits:
🔒 Security:
📝 PR Review Feedback Addressed:
editBasicInfofor consistency📊 Stats:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.