Skip to content
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

fix: when the api returns 401, the page is refreshed not as expected #4440

Merged
merged 1 commit into from
Sep 19, 2024

Conversation

anncwb
Copy link
Collaborator

@anncwb anncwb commented Sep 19, 2024

Description

fixed #4431

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs:dev command.
  • Run the tests with pnpm test.
  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • New Features
    • Enhanced logout functionality with error handling to prevent unhandled promise rejections.
  • Documentation
    • Updated drawer and modal documentation with guidance on using native or custom components.
    • Revised introduction document to clarify the flexibility of component usage.

@anncwb anncwb added the bug Something isn't working label Sep 19, 2024
@anncwb anncwb requested review from vince292007 and a team as code owners September 19, 2024 14:56
Copy link

changeset-bot bot commented Sep 19, 2024

⚠️ No Changeset found

Latest commit: 21cf44d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Sep 19, 2024

Walkthrough

The changes in this pull request primarily focus on enhancing the error handling of the logout function across multiple files in the auth.ts store. Each implementation now includes a try-catch block around the logoutApi() call, which prevents unhandled promise rejections if the API fails. Additionally, documentation updates have been made to improve user guidance regarding component usage and flexibility.

Changes

Files Change Summary
apps/web-antd/src/store/auth.ts Modified logout function to include error handling with a try-catch block around await logoutApi().
apps/web-ele/src/store/auth.ts Added error handling to logout function using a try-catch block around logoutApi() call.
apps/web-naive/src/store/auth.ts Updated logout function to wrap logoutApi() call in a try-catch block for error handling.
playground/src/store/auth.ts Introduced error handling in logout function with a try-catch block around the logoutApi() call.
docs/src/components/common-ui/vben-drawer.md Updated documentation to include guidance on missing parameter descriptions and flexibility in component usage.
docs/src/components/common-ui/vben-modal.md Enhanced documentation with notes on usage and encouraging exploration of online examples.
docs/src/components/introduction.md Rephrased guidance on using framework components to emphasize flexibility and user choice.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AuthStore
    participant API

    User->>AuthStore: Call logout()
    AuthStore->>API: await logoutApi()
    alt Error Occurs
        API-->>AuthStore: Error
        AuthStore->>AuthStore: // do nothing
    else Success
        API-->>AuthStore: Success
    end
    AuthStore->>AuthStore: resetAllStores()
    AuthStore->>AuthStore: setLoginExpired(false)
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure proper handling of 401 status code responses (#4431) The changes improve error handling but do not specifically address 401 errors.

Possibly related PRs

Suggested reviewers

  • vince292007

Poem

In the meadow, where bunnies play,
A logout fix has come our way.
With catches snug, no errors roam,
Our code is safe, our app's at home.
Hooray for changes, bright and new,
A smoother path for me and you! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Outside diff range and nitpick comments (1)
apps/web-ele/src/store/auth.ts (1)

80-84: Consider adding error logging or user feedback in the catch block.

The try-catch block is a good addition to handle potential errors from the logoutApi call and prevent disruptions in the application flow. However, silently catching the error without any logging or user feedback might make it difficult to identify and debug issues related to the logout process.

Consider adding error logging or user feedback in the catch block to help identify and debug potential issues with the logout process. For example:

    try {
      await logoutApi();
    } catch (error) {
-     // 不做任何处理
+     console.error('Error during logout:', error);
+     ElNotification({
+       message: $t('authentication.logoutError'),
+       title: $t('authentication.logoutFailed'),
+       type: 'error',
+     });
    }
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4765158 and 21cf44d.

Files selected for processing (7)
  • apps/web-antd/src/store/auth.ts (1 hunks)
  • apps/web-ele/src/store/auth.ts (1 hunks)
  • apps/web-naive/src/store/auth.ts (1 hunks)
  • docs/src/components/common-ui/vben-drawer.md (1 hunks)
  • docs/src/components/common-ui/vben-modal.md (1 hunks)
  • docs/src/components/introduction.md (1 hunks)
  • playground/src/store/auth.ts (1 hunks)
Files skipped from review due to trivial changes (2)
  • docs/src/components/common-ui/vben-modal.md
  • docs/src/components/introduction.md
Additional comments not posted (3)
playground/src/store/auth.ts (1)

80-84: Verify if the current implementation addresses the specific issue mentioned in the PR objectives.

The PR objectives mention fixing the issue of the frontend not being able to handle 401 responses properly, resulting in users having to refresh the page to be redirected to the login page. However, the current implementation does not seem to address this specific issue.

Please ensure that the changes made in this PR effectively handle the 401 response scenario and provide a smooth user experience without requiring a page refresh.

docs/src/components/common-ui/vben-drawer.md (2)

9-9: Good addition to guide users to online examples.

The note helpfully directs users to refer to online examples if parameter descriptions are missing in the documentation. This sets the right expectation that the docs may not be exhaustive while providing an alternative source of information.


11-15: Excellent framing of the framework's flexibility.

The introductory note does a great job of emphasizing the adaptability of the framework's components. By encouraging users to either leverage native components or create custom ones based on their needs, it promotes a flexible and empowering approach. The language used frames the components as enablers of the user's requirements rather than as constraints, which is a very positive message to convey.

apps/web-antd/src/store/auth.ts Show resolved Hide resolved
playground/src/store/auth.ts Show resolved Hide resolved
apps/web-naive/src/store/auth.ts Show resolved Hide resolved
@anncwb anncwb merged commit df48409 into main Sep 19, 2024
14 checks passed
@anncwb anncwb deleted the bugfix/4431 branch September 19, 2024 15:03
@github-actions github-actions bot locked and limited conversation to collaborators Oct 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: 后端返回401状态无法返回登录
1 participant