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

feat: Enhanced error handling in platfrom and API #765

Merged
merged 11 commits into from
Feb 18, 2025

Conversation

rajdip-b
Copy link
Member

@rajdip-b rajdip-b commented Feb 18, 2025

PR Type

Enhancement, Tests, Configuration changes, Documentation, Other


Description

  • Enhanced error handling across multiple services and components using constructErrorBody for consistent error messages.

  • Refactored platform components and API services to use the new useHttp hook for centralized API handling, improving error handling and user feedback.

  • Improved and simplified E2E tests for various modules, including Secret Controller, Workspace Membership, and Variable operations.

  • Added new utilities for authentication management, such as clearing auth cookies and logout functionality.

  • Updated ESLint configuration to allow non-null assertions and cleaned up unused imports for better code clarity.

  • Updated dependencies in pnpm-lock.yaml to remove redundant debug package versions.

  • Introduced a new error boundary component for API error handling and integrated Sentry for error reporting.

  • Added placeholder content for the Roles Page.


Changes walkthrough 📝

Relevant files
Tests
5 files
secret.e2e.spec.ts
Refactor and enhance Secret Controller E2E tests                 

apps/api/src/secret/secret.e2e.spec.ts

  • Rewrote the entire test suite for the Secret Controller.
  • Improved test cases for creating, updating, and deleting secrets.
  • Enhanced validation and error handling in tests.
  • Added new test cases for secret rotation and revisions.
  • +1161/-1173
    workspace-membership.e2e.spec.ts
    Simplify Workspace Membership E2E tests                                   

    apps/api/src/workspace-membership/workspace-membership.e2e.spec.ts

  • Simplified error validation in workspace membership tests.
  • Removed redundant error message checks.
  • +2/-65   
    environment.e2e.spec.ts
    Clean up Environment E2E test setup                                           

    apps/api/src/environment/environment.e2e.spec.ts

  • Commented out unused imports for SecretService and VariableService.
  • Simplified test setup by removing unused service initialization.
  • +6/-20   
    variable.e2e.spec.ts
    Enhance Variable E2E tests                                                             

    apps/api/src/variable/variable.e2e.spec.ts

  • Removed redundant error message checks in variable tests.
  • Added new test case for updating variables with empty names.
  • +20/-26 
    feedback.e2e.spec.ts
    Updated Feedback E2E Test for new error handling                 

    apps/api/src/feedback/feedback.e2e.spec.ts

    • Updated test case to align with new error handling.
    +1/-6     
    Enhancement
    48 files
    workspace-role.service.ts
    Improve error handling in Workspace Role Service                 

    apps/api/src/workspace-role/service/workspace-role.service.ts

  • Replaced plain error messages with constructErrorBody for better error
    structure.
  • Improved error handling for workspace role creation and updates.
  • Enhanced validation for environment and project-related operations.
  • +62/-17 
    authority-checker.service.ts
    Enhance Authority Checker Service error handling                 

    apps/api/src/common/authority-checker.service.ts

  • Replaced plain error messages with constructErrorBody for better error
    structure.
  • Removed redundant userId parameter from permission checks.
  • Improved error handling for workspace, project, and environment
    validation.
  • +51/-21 
    workspace-membership.service.ts
    Improve error handling in Workspace Membership Service     

    apps/api/src/workspace-membership/service/workspace-membership.service.ts

  • Replaced plain error messages with constructErrorBody for better error
    structure.
  • Improved error handling for workspace membership operations.
  • Enhanced validation for ownership transfer and role assignments.
  • +59/-14 
    page.tsx
    Refactor OTP page logic and error handling                             

    apps/platform/src/app/auth/otp/page.tsx

  • Refactored OTP validation and resend logic using useHttp hook.
  • Simplified error handling and removed redundant state variables.
  • Improved user feedback with better toast messages.
  • +47/-79 
    index.tsx
    Refactor Edit Project Sheet logic                                               

    apps/platform/src/components/dashboard/project/editProjectSheet/index.tsx

  • Refactored project update logic using useHttp hook.
  • Simplified state management and removed redundant logic.
  • Improved user feedback with better toast messages.
  • +51/-83 
    combobox.tsx
    Refactor Combobox component logic                                               

    apps/platform/src/components/ui/combobox.tsx

  • Refactored workspace fetching and creation logic using useHttp hook.
  • Simplified state management and removed redundant error handling.
  • Improved user feedback with better toast messages.
  • +44/-99 
    index.tsx
    Refactor Edit Variable Sheet logic                                             

    apps/platform/src/components/dashboard/variable/editVariableSheet/index.tsx

  • Refactored variable update logic using useHttp hook.
  • Simplified state management and removed redundant logic.
  • Improved user feedback with better toast messages.
  • +65/-82 
    variable.service.ts
    Enhance error handling in Variable Service                             

    apps/api/src/variable/service/variable.service.ts

  • Replaced plain error messages with constructErrorBody for better error
    structure.
  • Improved error handling for variable creation and rollback operations.
  • +13/-4   
    index.tsx
    Refactored Add Environment Dialogue for better API handling

    apps/platform/src/components/dashboard/environment/addEnvironmentDialogue/index.tsx

  • Introduced useHttp hook for API calls.
  • Added loading state management with isLoading.
  • Simplified API call logic and error handling.
  • Disabled button during loading state.
  • +50/-73 
    index.tsx
    Enhanced Edit Environment Sheet with better API handling 

    apps/platform/src/components/dashboard/environment/editEnvironmentSheet/index.tsx

  • Integrated useHttp hook for API calls.
  • Added isLoading state for managing loading indicators.
  • Improved error handling and removed redundant code.
  • Disabled save button during loading state.
  • +48/-63 
    index.tsx
    Refactored Edit Secret Sheet for improved API handling     

    apps/platform/src/components/dashboard/secret/editSecretSheet/index.tsx

  • Refactored to use useHttp for API calls.
  • Added isLoading state for better user feedback.
  • Improved error handling and removed redundant code.
  • Disabled save button during loading state.
  • +61/-69 
    page.tsx
    Enhanced Profile Page with delete functionality and better API
    handling

    apps/platform/src/app/(main)/(settings)/settings/@profile/page.tsx

  • Added useHttp for API calls.
  • Introduced delete profile functionality.
  • Improved error handling and loading state management.
  • Added useEffect to fetch user profile data.
  • +63/-34 
    index.tsx
    Refactored Add Variable Dialogue for better API handling 

    apps/platform/src/components/dashboard/variable/addVariableDialogue/index.tsx

  • Integrated useHttp for API calls.
  • Added isLoading state for better user feedback.
  • Simplified API logic and error handling.
  • Disabled button during loading state.
  • +53/-67 
    index.tsx
    Enhanced Add Secret Dialogue with improved API handling   

    apps/platform/src/components/dashboard/secret/addSecretDialogue/index.tsx

  • Refactored to use useHttp for API calls.
  • Added isLoading state for better user feedback.
  • Simplified API logic and error handling.
  • Disabled button during loading state.
  • +49/-60 
    index.tsx
    Enhanced Confirm Delete Environment with better API handling

    apps/platform/src/components/dashboard/environment/confirmDeleteEnvironment/index.tsx

  • Integrated useHttp for API calls.
  • Added isLoading state for managing loading indicators.
  • Improved error handling and removed redundant code.
  • Disabled delete button during loading state.
  • +52/-50 
    index.tsx
    Improved Confirm Delete Secret with better API handling   

    apps/platform/src/components/dashboard/secret/confirmDeleteSecret/index.tsx

  • Refactored to use useHttp for API calls.
  • Added isLoading state for better user feedback.
  • Simplified API logic and error handling.
  • Disabled delete button during loading state.
  • +44/-53 
    index.tsx
    Enhanced Confirm Delete Project with better API handling 

    apps/platform/src/components/dashboard/project/confirmDeleteProject/index.tsx

  • Integrated useHttp for API calls.
  • Added isLoading state for managing loading indicators.
  • Improved error handling and removed redundant code.
  • Disabled delete button during loading state.
  • +46/-52 
    index.tsx
    Improved Create Project Dialogue with better API handling

    apps/platform/src/components/dashboard/project/createProjectDialogue/index.tsx

  • Refactored to use useHttp for API calls.
  • Added isLoading state for better user feedback.
  • Simplified API logic and error handling.
  • Disabled create button during loading state.
  • +46/-46 
    index.tsx
    Enhanced Confirm Delete Variable with better API handling

    apps/platform/src/components/dashboard/variable/confirmDeleteVariable/index.tsx

  • Integrated useHttp for API calls.
  • Added isLoading state for managing loading indicators.
  • Improved error handling and removed redundant code.
  • Disabled delete button during loading state.
  • +48/-48 
    page.tsx
    Refactored Secret Page for better API handling                     

    apps/platform/src/app/(main)/(project)/[workspace]/[project]/@secret/page.tsx

  • Refactored to use useHttp for fetching secrets.
  • Simplified API logic and removed redundant error handling.
  • Improved loading state management.
  • +20/-43 
    page.tsx
    Enhanced Main Page with better API handling                           

    apps/platform/src/app/(main)/page.tsx

  • Integrated useHttp for fetching projects and user data.
  • Simplified API logic and removed redundant error handling.
  • Improved loading state management.
  • +29/-53 
    layout.tsx
    Improved Project Layout with better API handling                 

    apps/platform/src/app/(main)/(project)/[workspace]/[project]/layout.tsx

  • Refactored to use useHttp for fetching project and environment data.
  • Simplified API logic and removed redundant error handling.
  • +26/-59 
    project.service.ts
    Enhanced Project Service with consistent error handling   

    apps/api/src/project/service/project.service.ts

  • Introduced constructErrorBody for consistent error messages.
  • Enhanced error handling with detailed messages.
  • Improved readability and maintainability of error logic.
  • +29/-7   
    error-component.tsx
    Introduced Error Boundary Component for API error handling

    apps/platform/src/app/error-component.tsx

  • Added a new error boundary component for handling API errors.
  • Integrated Sentry for error reporting.
  • Improved user feedback for various error scenarios.
  • +96/-0   
    page.tsx
    Enhanced Auth Page with better OTP handling                           

    apps/platform/src/app/auth/page.tsx

  • Refactored to use useHttp for sending OTP.
  • Improved error handling and loading state management.
  • Simplified API logic and removed redundant code.
  • +14/-30 
    secret.service.ts
    Improved Secret Service with consistent error handling     

    apps/api/src/secret/service/secret.service.ts

  • Introduced constructErrorBody for consistent error messages.
  • Enhanced error handling with detailed messages.
  • Improved readability and maintainability of error logic.
  • +25/-6   
    user.service.ts
    Enhanced User Service with consistent error handling         

    apps/api/src/user/service/user.service.ts

  • Added constructErrorBody for consistent error messages.
  • Enhanced error handling with detailed messages.
  • Improved readability and maintainability of error logic.
  • +33/-6   
    page.tsx
    Improved Environment Page with better API handling             

    apps/platform/src/app/(main)/(project)/[workspace]/[project]/@environment/page.tsx

  • Refactored to use useHttp for fetching environments.
  • Simplified API logic and removed redundant error handling.
  • +15/-44 
    page.tsx
    Enhanced Variable Page with better API handling                   

    apps/platform/src/app/(main)/(project)/[workspace]/[project]/@variable/page.tsx

  • Refactored to use useHttp for fetching variables.
  • Simplified API logic and removed redundant error handling.
  • +15/-44 
    page.tsx
    Enhanced Account Details Page with better API handling     

    apps/platform/src/app/auth/account-details/page.tsx

  • Refactored to use useHttp for updating user details.
  • Improved error handling and loading state management.
  • Simplified API logic and removed redundant code.
  • +13/-30 
    api-key.service.ts
    Improved API Key Service with consistent error handling   

    apps/api/src/api-key/service/api-key.service.ts

  • Added constructErrorBody for consistent error messages.
  • Enhanced error handling with detailed messages.
  • Improved readability and maintainability of error logic.
  • +27/-5   
    workspace.service.ts
    Enhanced Workspace Service with consistent error handling

    apps/api/src/workspace/service/workspace.service.ts

  • Introduced constructErrorBody for consistent error messages.
  • Enhanced error handling with detailed messages.
  • Improved readability and maintainability of error logic.
  • +17/-4   
    variable.ts
    Updated Variable Controller for optional headers                 

    packages/api-client/src/controllers/variable.ts

  • Made headers optional in API client methods.
  • Improved flexibility for API calls.
  • +6/-6     
    integration.service.ts
    Improved Integration Service with consistent error handling

    apps/api/src/integration/service/integration.service.ts

  • Added constructErrorBody for consistent error messages.
  • Enhanced error handling with detailed messages.
  • Improved readability and maintainability of error logic.
  • +13/-4   
    api-key.guard.ts
    Enhanced API Key Guard with consistent error handling       

    apps/api/src/auth/guard/api-key/api-key.guard.ts

  • Introduced constructErrorBody for consistent error messages.
  • Enhanced error handling with detailed messages.
  • Improved readability and maintainability of error logic.
  • +17/-3   
    auth.service.ts
    Improved Auth Service with consistent error handling         

    apps/api/src/auth/service/auth.service.ts

  • Added constructErrorBody for consistent error messages.
  • Enhanced error handling with detailed messages.
  • Improved readability and maintainability of error logic.
  • +13/-3   
    use-http.ts
    Introduced useHttp Hook for API handling                                 

    apps/platform/src/hooks/use-http.ts

  • Added a new useHttp hook for consistent API handling.
  • Centralized error handling for API responses.
  • Integrated Sentry for error reporting.
  • +56/-0   
    auth.guard.ts
    Enhanced Auth Guard with consistent error handling             

    apps/api/src/auth/guard/auth/auth.guard.ts

  • Added constructErrorBody for consistent error messages.
  • Enhanced error handling with detailed messages.
  • Improved readability and maintainability of error logic.
  • +13/-2   
    base.integration.ts
    Improved Base Integration with consistent error handling 

    apps/api/src/integration/plugins/base.integration.ts

  • Introduced constructErrorBody for consistent error messages.
  • Enhanced error handling with detailed messages.
  • Improved readability and maintainability of error logic.
  • +9/-2     
    environment.ts
    Enhanced Environment Utility with consistent error handling

    apps/api/src/common/environment.ts

  • Added constructErrorBody for consistent error messages.
  • Enhanced error handling with detailed messages.
  • Improved readability and maintainability of error logic.
  • +11/-2   
    environment.service.ts
    Improved Environment Service with consistent error handling

    apps/api/src/environment/service/environment.service.ts

  • Added constructErrorBody for consistent error messages.
  • Enhanced error handling with detailed messages.
  • Improved readability and maintainability of error logic.
  • +9/-3     
    event.service.ts
    Enhanced Event Service with consistent error handling       

    apps/api/src/event/service/event.service.ts

  • Introduced constructErrorBody for consistent error messages.
  • Enhanced error handling with detailed messages.
  • Improved readability and maintainability of error logic.
  • +7/-3     
    feedback.service.ts
    Improved Feedback Service with consistent error handling 

    apps/api/src/feedback/service/feedback.service.ts

  • Added constructErrorBody for consistent error messages.
  • Enhanced error handling with detailed messages.
  • +7/-1     
    user.ts
    Enhanced User Utility with consistent error handling         

    apps/api/src/common/user.ts

  • Added constructErrorBody for consistent error messages.
  • Enhanced error handling with detailed messages.
  • +4/-1     
    slug-generator.ts
    Enhanced Slug Generator with better error handling             

    apps/api/src/common/slug-generator.ts

  • Replaced generic error with InternalServerErrorException.
  • Improved error handling for invalid slug suffixes.
  • +4/-1     
    util.ts
    Introduced utility for constructing error messages             

    apps/api/src/common/util.ts

    • Added constructErrorBody utility for consistent error messages.
    +15/-0   
    utils.ts
    Introduced logout utility for clearing auth data                 

    apps/platform/src/lib/utils.ts

    • Added logout function for clearing authentication data.
    +8/-0     
    clear-auth-cookie.ts
    Introduced utility for clearing auth cookies                         

    apps/platform/src/lib/clear-auth-cookie.ts

    • Added utility to clear authentication cookies.
    +10/-0   
    Formatting
    2 files
    create.variable.ts
    Cleaned up Create Variable DTO imports                                     

    apps/api/src/variable/dto/create.variable/create.variable.ts

    • Simplified imports by removing unused decorators.
    +2/-9     
    index.tsx
    Cleaned up Navbar component imports                                           

    apps/platform/src/components/shared/navbar/index.tsx

    • Removed unused imports for better code clarity.
    +1/-3     
    Miscellaneous
    1 files
    page.tsx
    Added placeholder for Roles Page                                                 

    apps/platform/src/app/(main)/roles/page.tsx

    • Added placeholder content for roles page.
    +1/-1     
    Dependencies
    1 files
    pnpm-lock.yaml
    Updated dependencies in pnpm-lock file                                     

    pnpm-lock.yaml

    • Updated dependencies to remove redundant debug package versions.
    +10/-6   
    Configuration changes
    1 files
    .eslintrc.cjs
    Updated ESLint configuration for non-null assertions         

    apps/platform/.eslintrc.cjs

    • Disabled @typescript-eslint/no-non-null-assertion rule.
    +2/-1     
    Additional files
    6 files
    auth.e2e.spec.ts +0/-2     
    integration.e2e.spec.ts +0/-6     
    project.e2e.spec.ts +0/-55   
    create.secret.ts +0/-2     
    user.e2e.spec.ts +0/-15   
    workspace.e2e.spec.ts +0/-25   

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling

    The error handling in the OTP validation flow has been simplified and some error messages/cases may have been removed. Verify that all important error scenarios are still properly handled and communicated to users.

    const { success, data } = await validateOTP()
    
    if (success && data) {
      setUser(data)
    Authorization Check

    The workspace membership service has multiple authorization checks that were modified to use constructErrorBody. Verify that all authorization checks are still properly enforced and error messages are appropriate.

    // Check if the user is the owner of the workspace
    if (workspaceOwnerId === user.id)
      throw new BadRequestException(
        constructErrorBody(
          'Can not leave workspace',
          'You cannot leave the workspace as you are the owner of the workspace. Please transfer the ownership to another member before leaving the workspace.'
        )
      )
    Permission Validation

    The authority checker service was modified to remove userId parameter from checkHasPermissionOverEntity. Verify that permissions are still properly validated without this parameter.

     */
    private checkHasPermissionOverEntity(
      permittedAuthorities: Set<Authority>,
      authorities: Authority[]
    ): void {

    Copy link
    Contributor

    codiumai-pr-agent-free bot commented Feb 18, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Uncomment and fix rollback test

    The rollback test case is commented out, preventing proper validation of the
    rollback functionality. Uncomment and fix the assertions to properly test the
    rollback feature.

    apps/api/src/secret/secret.e2e.spec.ts [605-622]

    -// eslint-disable-next-line @typescript-eslint/no-unused-vars
     const response = await app.inject({
       method: 'PUT',
       url: `/secret/${secret1.slug}/rollback/1?environmentSlug=${environment1.slug}`,
       headers: {
         'x-e2e-user-email': user1.email
       }
     })
     
    -// expect(response.json().count).toEqual(2)
    +expect(response.statusCode).toBe(200)
    +expect(response.json().count).toEqual(2)
     
    -// versions = await prisma.secretVersion.findMany({
    -//   where: {
    -//     secretId: secret1.id
    -//   }
    -// })
    +versions = await prisma.secretVersion.findMany({
    +  where: {
    +    secretId: secret1.id
    +  }
    +})
     
    -// expect(versions.length).toBe(1)
    +expect(versions.length).toBe(1)
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    __

    Why: The commented out test code prevents proper validation of the critical rollback functionality. Uncommenting and fixing the assertions is important to ensure the rollback feature works correctly.

    Medium
    Remove duplicate state updates
    Suggestion Impact:The commit removed the duplicate setIsLoading(false) call as suggested

    code diff:

    -
    -    setIsLoading(false)

    The error handling flow has duplicate state updates. The setIsLoading(false) is
    called both in the try-finally block and after it, which could lead to race
    conditions.

    apps/platform/src/app/auth/otp/page.tsx [105-111]

     } finally {
       setIsLoading(false)
       setIsLoadingRefresh(false)
       toast.dismiss()
     }
     
    -setIsLoading(false)
    -

    [Suggestion has been applied]

    Suggestion importance[1-10]: 8

    __

    Why: The suggestion fixes a potential race condition by removing redundant state updates. This is a significant improvement as it prevents possible bugs in the application's state management.

    Medium
    Handle workspace creation failure case

    Add error handling for the case when workspace creation fails. Currently, if
    createWorkspace() fails, the error is silently ignored and the loading state
    remains active.

    apps/platform/src/components/ui/combobox.tsx [72-83]

     try {
    -  const { success, data } = await createWorkspace()
    +  const { success, data, error } = await createWorkspace()
     
       if (success && data) {
         toast.success('Workspace created successfully')
         setSelectedWorkspace({ ...data, projects: 0 })
         setOpen(false)
    +  } else if (error) {
    +    toast.error('Failed to create workspace', {
    +      description: error.message
    +    })
       }
     } finally {
       setIsLoading(false)
       toast.dismiss()
     }

    [To ensure code accuracy, apply this suggestion manually]

    Suggestion importance[1-10]: 8

    __

    Why: Important improvement to handle API error cases that are currently ignored. Adding proper error handling with user feedback improves reliability and user experience.

    Medium
    Fix form field update handler
    Suggestion Impact:The commit implemented the suggested change by updating both Input and Textarea onChange handlers to use e.target.id instead of e.target.name

    code diff:

    @@ -137,7 +137,7 @@
                 <Input
                   className="col-span-3 h-[2.75rem]"
                   id="name"
    -              onChange={(e) => updateRequestData(e.target.name, e.target.value)}
    +              onChange={(e) => updateRequestData(e.target.id, e.target.value)}
                   placeholder="Enter the name of the variable"
                   value={requestData.name}
                 />
    @@ -150,7 +150,7 @@
                 <Textarea
                   className="col-span-3 h-[2.75rem]"
                   id="name"
    -              onChange={(e) => updateRequestData(e.target.name, e.target.value)}
    +              onChange={(e) => updateRequestData(e.target.id, e.target.value)}
                   placeholder="Enter the note of the variable"
                   value={requestData.note}
                 />

    The onChange event handlers for Input and Textarea components are using the
    wrong event target property. They should use e.target.id instead of
    e.target.name to match the form field IDs.

    apps/platform/src/components/dashboard/variable/editVariableSheet/index.tsx [137-143]

     <Input
       className="col-span-3 h-[2.75rem]"
       id="name"
    -  onChange={(e) => updateRequestData(e.target.name, e.target.value)}
    +  onChange={(e) => updateRequestData(e.target.id, e.target.value)}
       placeholder="Enter the name of the variable"
       value={requestData.name}
     />

    [To ensure code accuracy, apply this suggestion manually]

    Suggestion importance[1-10]: 7

    __

    Why: Critical bug fix - using e.target.name instead of e.target.id would cause the form updates to fail since the field IDs are used as keys.

    Medium
    General
    Improve error message clarity
    Suggestion Impact:The commit implemented exactly the suggested changes, replacing duplicate error messages with a distinct title and description for environment slugs validation

    code diff:

    -                `EnvironmentSlugs in the project ${pe.projectSlug} are required`,
    -                `EnvironmentSlugs in the project ${pe.projectSlug} are required`
    +                'Missing environment slugs',
    +                `Environment slugs must be specified for project ${pe.projectSlug}`

    The error title and message in constructErrorBody are identical for environment
    slugs validation. Consider using distinct messages to provide clearer error
    context.

    apps/api/src/workspace-role/service/workspace-role.service.ts [325-330]

     throw new BadRequestException(
       constructErrorBody(
    -    `EnvironmentSlugs in the project ${pe.projectSlug} are required`,
    -    `EnvironmentSlugs in the project ${pe.projectSlug} are required`
    +    'Missing environment slugs',
    +    `Environment slugs must be specified for project ${pe.projectSlug}`
       )
     )

    [Suggestion has been applied]

    Suggestion importance[1-10]: 6

    __

    Why: The suggestion improves error message clarity by differentiating between the error title and description, making it easier for users to understand the issue. The impact is moderate as it enhances user experience without affecting functionality.

    Low
    Validate profile changes before update

    The profile update logic should validate that at least one field (name or email)
    has changed before making the API call, to avoid unnecessary server requests.

    apps/platform/src/app/(main)/(settings)/settings/@profile/page.tsx [58-74]

     const handleUpdateSelf = useCallback(async () => {
    +  if (userData.name === user?.name && userData.email === user?.email) {
    +    toast.error('No changes to update')
    +    return
    +  }
    +
       toast.loading('Updating profile...')
       setIsLoading(true)
     
       try {
         const { success, data } = await updateSelf()
     
         if (success && data) {
           toast.success('Profile updated successfully!')
           setUser(data)
         }
       } finally {
         setIsLoading(false)
         setIsModified(false)
         toast.dismiss()
       }
    -}, [updateSelf, setUser])
    +}, [updateSelf, setUser, userData, user])
    • Apply this suggestion
    Suggestion importance[1-10]: 5

    __

    Why: Useful optimization to prevent unnecessary API calls when no actual changes were made to the profile data.

    Low
    • Update

    @rajdip-b rajdip-b merged commit b4349ad into develop Feb 18, 2025
    7 checks passed
    @rajdip-b rajdip-b deleted the refactor/enhanced-platform-error-handling branch February 18, 2025 07:40
    rajdip-b pushed a commit that referenced this pull request Feb 18, 2025
    ## [2.12.0-stage.5](v2.12.0-stage.4...v2.12.0-stage.5) (2025-02-18)
    
    ### 🚀 Features
    
    * Enhanced error handling in platfrom and API ([#765](#765)) ([b4349ad](b4349ad))
    @rajdip-b
    Copy link
    Member Author

    🎉 This PR is included in version 2.12.0-stage.5 🎉

    The release is available on GitHub release

    Your semantic-release bot 📦🚀

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant