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(auth-admin): Show relevant error messages #16180

Merged
merged 9 commits into from
Sep 30, 2024

Conversation

magnearun
Copy link
Contributor

@magnearun magnearun commented Sep 26, 2024

What

Show relevant error messages in create form

Why

Help user fix errors

Screenshots / Gifs

Attach Screenshots / Gifs to help reviewers understand the scope of the pull request

Checklist:

  • I have performed a self-review of my own code
  • 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
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features

    • Enhanced error handling during delegation creation with dynamic error messages.
    • Introduced structured error codes for better clarity on validation issues.
    • Added new error messages to provide specific feedback for various scenarios.
    • New error codes implemented for improved error reporting.
  • Bug Fixes

    • Improved feedback for users encountering errors during the delegation process.

Copy link
Contributor

coderabbitai bot commented Sep 26, 2024

Walkthrough

The changes enhance error handling in the delegation process by modifying the DelegationAdminCustomService to include structured error responses with specific error codes. A new errors.ts file maps these error codes to user-friendly messages. Additionally, the createDelegationAction function has been updated to better handle Apollo errors, and the user interface now displays dynamic error messages based on the presence of specific error details.

Changes

File Change Summary
libs/auth-api-lib/src/lib/delegations/admin/delegation-admin-custom.service.ts Enhanced error handling by including structured error objects with specific error codes for various validation scenarios.
libs/portals/admin/delegation-admin/src/constants/errors.ts Introduced a new errors.ts file that exports FORM_ERRORS, mapping error codes to corresponding messages for improved error reporting.
libs/portals/admin/delegation-admin/src/lib/messages.ts Added new message definitions related to error handling and validation scenarios for delegation processes.
libs/portals/admin/delegation-admin/src/screens/CreateDelegation/CreateDelegation.action.ts Improved error handling by integrating Apollo error handling and updating CreateDelegationResult to include an optional problem property.
libs/portals/admin/delegation-admin/src/screens/CreateDelegation/CreateDelegation.tsx Updated AlertMessage to conditionally display error messages based on actionData?.problem, enhancing dynamic feedback.

Possibly related PRs

Suggested reviewers

  • GunnlaugurG

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5944ce0 and 2831927.

📒 Files selected for processing (1)
  • libs/auth-api-lib/src/lib/delegations/admin/delegation-admin-custom.service.ts (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/auth-api-lib/src/lib/delegations/admin/delegation-admin-custom.service.ts

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.

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.

@datadog-island-is
Copy link

datadog-island-is bot commented Sep 26, 2024

Datadog Report

All test runs 5e45ccd 🔗

68 Total Test Services: 0 Failed, 66 Passed
🔻 Test Sessions change in coverage: 2 decreased, 18 increased, 180 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
air-discount-scheme-backend 0 0 0 81 0 31.71s N/A Link
air-discount-scheme-web 0 0 0 2 0 8.77s 1 no change Link
api 0 0 0 4 0 3.06s N/A Link
api-domains-air-discount-scheme 0 0 0 6 0 20.18s 1 no change Link
api-domains-assets 0 0 0 3 0 12.99s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 12.4s N/A Link
api-domains-communications 0 0 0 5 0 27.16s 1 increased (+0.06%) Link
api-domains-criminal-record 0 0 0 5 0 8.67s 1 no change Link
api-domains-driving-license 0 0 0 23 0 40.48s 1 increased (+0.07%) Link
api-domains-education 0 0 0 8 0 27.71s 1 increased (+0.23%) Link

🔻 Code Coverage Decreases vs Default Branch (2)

  • shared-utils - jest 28.94% (-1.06%) - Details
  • services-university-gateway - jest 44.87% (-0.01%) - Details

Copy link

codecov bot commented Sep 26, 2024

Codecov Report

Attention: Patch coverage is 68.75000% with 5 lines in your changes missing coverage. Please review.

Project coverage is 36.70%. Comparing base (c590e28) to head (2831927).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...legations/admin/delegation-admin-custom.service.ts 37.50% 5 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16180   +/-   ##
=======================================
  Coverage   36.69%   36.70%           
=======================================
  Files        6778     6779    +1     
  Lines      139683   139692    +9     
  Branches    39723    39741   +18     
=======================================
+ Hits        51259    51268    +9     
  Misses      88424    88424           
Flag Coverage Δ
air-discount-scheme-backend 54.23% <100.00%> (+0.10%) ⬆️
air-discount-scheme-web 0.00% <ø> (ø)
api 3.39% <ø> (ø)
api-domains-air-discount-scheme 36.91% <ø> (ø)
api-domains-assets 26.71% <ø> (ø)
api-domains-auth-admin 48.77% <ø> (ø)
api-domains-communications 40.01% <100.00%> (+0.05%) ⬆️
api-domains-criminal-record 47.85% <ø> (ø)
api-domains-driving-license 44.47% <100.00%> (+0.12%) ⬆️
api-domains-education 31.67% <100.00%> (+0.27%) ⬆️
api-domains-health-insurance 34.68% <ø> (ø)
api-domains-mortgage-certificate 35.70% <ø> (ø)
api-domains-payment-schedule 41.20% <ø> (ø)
application-api-files 57.86% <100.00%> (+0.21%) ⬆️
application-core 71.62% <ø> (+0.32%) ⬆️
application-system-api 41.64% <100.00%> (+0.01%) ⬆️
application-template-api-modules 23.74% <100.00%> (+0.03%) ⬆️
application-templates-accident-notification 22.14% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 26.63% <ø> (ø)
application-templates-driving-license 18.70% <ø> (ø)
application-templates-estate 12.34% <ø> (ø)
application-templates-example-payment 25.41% <ø> (ø)
application-templates-financial-aid 14.34% <ø> (ø)
application-templates-general-petition 23.68% <ø> (ø)
application-templates-health-insurance 26.62% <ø> (ø)
application-templates-inheritance-report 6.45% <ø> (ø)
application-templates-marriage-conditions 15.23% <ø> (ø)
application-templates-mortgage-certificate 43.96% <ø> (ø)
application-templates-parental-leave 30.15% <ø> (ø)
application-types 6.71% <ø> (ø)
application-ui-components 1.28% <ø> (ø)
application-ui-shell 21.29% <ø> (ø)
auth-react 22.80% <ø> (ø)
clients-charge-fjs-v2 24.11% <ø> (ø)
clients-driving-license 40.65% <ø> (ø)
clients-driving-license-book 43.91% <ø> (ø)
clients-financial-statements-inao 49.17% <ø> (ø)
clients-license-client 1.83% <ø> (ø)
clients-middlewares 73.11% <100.00%> (+0.61%) ⬆️
clients-regulations 42.63% <ø> (ø)
clients-rsk-company-registry 29.76% <ø> (ø)
clients-syslumenn 49.66% <ø> (ø)
cms 0.43% <ø> (ø)
cms-translations 39.14% <100.00%> (+0.05%) ⬆️
contentful-apps 5.76% <ø> (ø)
download-service 44.75% <100.00%> (+0.11%) ⬆️
financial-aid-backend 56.54% <ø> (ø)
financial-aid-shared 19.03% <ø> (ø)
island-ui-core 28.47% <ø> (ø)
judicial-system-api 18.46% <ø> (ø)
judicial-system-backend 54.84% <100.00%> (+0.01%) ⬆️
judicial-system-web 28.16% <ø> (ø)
license-api 42.61% <100.00%> (+0.08%) ⬆️
portals-admin-regulations-admin 1.88% <ø> (ø)
portals-core 16.17% <ø> (ø)
services-auth-admin-api 51.98% <68.75%> (+0.03%) ⬆️
services-auth-delegation-api 57.94% <62.50%> (+0.10%) ⬆️
services-auth-ids-api 51.87% <62.50%> (+0.04%) ⬆️
services-auth-personal-representative 45.52% <62.50%> (+0.01%) ⬆️
services-auth-personal-representative-public 41.59% <62.50%> (+0.01%) ⬆️
services-auth-public-api 49.37% <62.50%> (+0.04%) ⬆️
services-endorsements-api 55.23% <100.00%> (+0.10%) ⬆️
services-university-gateway 48.42% <ø> (-0.12%) ⬇️
services-user-notification 47.17% <100.00%> (+0.03%) ⬆️
services-user-profile 62.37% <100.00%> (+0.07%) ⬆️
shared-components 27.68% <ø> (ø)
shared-form-fields 31.61% <ø> (ø)
shared-utils 28.01% <0.00%> (-0.91%) ⬇️
web 1.83% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
libs/shared/utils/src/index.ts 100.00% <100.00%> (ø)
libs/shared/utils/src/lib/errorCodes.ts 100.00% <100.00%> (ø)
...legations/admin/delegation-admin-custom.service.ts 90.58% <37.50%> (+0.11%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c590e28...2831927. Read the comment docs.

@magnearun magnearun marked this pull request as ready for review September 26, 2024 16:09
@magnearun magnearun requested a review from a team as a code owner September 26, 2024 16:09
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: 0

🧹 Outside diff range and nitpick comments (2)
libs/portals/admin/delegation-admin/src/screens/CreateDelegation/CreateDelegation.action.ts (1)

97-102: Improved error handling in createDelegationAction

The new error handling logic using findProblemInApolloError provides more specific error information, aligning with the PR objective of showing relevant error messages. This enhancement will improve the user experience by providing more detailed feedback.

Consider adding a fallback message for clarity:

errorMessage: problem?.detail || 'An unexpected error occurred',

This ensures that users always receive some form of error message, even if problem.detail is undefined.

libs/portals/admin/delegation-admin/src/screens/CreateDelegation/CreateDelegation.tsx (1)

408-410: Approve changes with a minor suggestion for improvement

The changes effectively implement the PR objective of showing relevant error messages, improving the user experience by providing more specific feedback when available. This implementation aligns well with the coding guidelines for TypeScript usage and doesn't affect the component's reusability or tree-shaking capabilities.

To further improve code clarity and maintainability, consider using the nullish coalescing operator (??) instead of the logical OR (||). This would more explicitly handle cases where actionData?.errorMessage might be an empty string:

message={actionData?.errorMessage ?? formatMessage(m.errorDefault)}

This change ensures that the default message is used only when actionData?.errorMessage is null or undefined, not when it's an empty string (which might be a valid error message in some cases).

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 55d69bb and acd3822.

📒 Files selected for processing (2)
  • libs/portals/admin/delegation-admin/src/screens/CreateDelegation/CreateDelegation.action.ts (3 hunks)
  • libs/portals/admin/delegation-admin/src/screens/CreateDelegation/CreateDelegation.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
libs/portals/admin/delegation-admin/src/screens/CreateDelegation/CreateDelegation.action.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/portals/admin/delegation-admin/src/screens/CreateDelegation/CreateDelegation.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🔇 Additional comments (3)
libs/portals/admin/delegation-admin/src/screens/CreateDelegation/CreateDelegation.action.ts (3)

14-17: Improved error handling with shared utilities

The addition of findProblemInApolloError and ProblemType from the shared problem package aligns well with the PR objective of showing relevant error messages. This also adheres to the coding guideline of promoting reusability across different NextJS apps.


57-57: Enhanced error reporting in CreateDelegationResult type

The addition of the optional errorMessage property to the CreateDelegationResult type enhances error reporting capabilities, aligning with the PR objective of showing relevant error messages. This change also adheres to the TypeScript usage guideline for defining types.


Line range hint 1-105: Summary: Effective implementation of error handling improvements

The changes in this file successfully implement improved error handling and align well with the PR objectives and coding guidelines. The use of shared utilities, TypeScript types, and detailed error reporting enhances the overall quality and user experience of the application.

To ensure the effectiveness of these changes:

Please run the following script to check for consistent error handling across the codebase:

This will help identify any other locations where similar error handling improvements could be applied for consistency.

✅ Verification successful

It looks like the previous script encountered an error due to an unrecognized file type. Let's adjust the script to correctly target TypeScript files.


Verification Successful: Consistent Error Handling Confirmed

The use of findProblemInApolloError within catch blocks has been consistently implemented across the codebase, including in the reviewed file CreateDelegation.action.ts and PeriodsRepeater/index.tsx. No discrepancies were found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent use of findProblemInApolloError in catch blocks

# Test: Search for catch blocks and verify they use findProblemInApolloError
rg --type typescript 'catch.*\{' -A 5 | rg 'findProblemInApolloError'

Length of output: 104


Script:

#!/bin/bash
# Description: Check for consistent use of findProblemInApolloError in catch blocks

# Test: Search for catch blocks and verify they use findProblemInApolloError
rg -g "*.ts" -g "*.tsx" 'catch\s*\(.*\)\s*\{' -A 5 | rg 'findProblemInApolloError'

Length of output: 362

@magnearun magnearun requested review from a team as code owners September 27, 2024 15:26
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: 4

🧹 Outside diff range and nitpick comments (5)
libs/shared/utils/src/lib/errorCodes.ts (1)

1-8: LGTM! Consider adding documentation for each error code.

The ErrorCodes enum is well-structured and follows TypeScript best practices. It's properly exported and uses a consistent naming convention. To improve maintainability and assist library consumers, consider adding JSDoc comments explaining the purpose and usage of each error code.

Example of how you could add documentation:

export enum ErrorCodes {
  /** Mismatch between national IDs in Zendesk */
  ZENDESK_NATIONAL_IDS_MISMATCH = 'ZENDESK_NATIONAL_IDS_MISMATCH',
  /** Required custom fields are missing in Zendesk */
  ZENDESK_CUSTOM_FIELDS_MISSING = 'ZENDESK_CUSTOM_FIELDS_MISSING',
  // ... (add comments for other error codes)
}
libs/portals/admin/delegation-admin/src/constants/errors.ts (1)

1-2: Consider using a more descriptive import name.

The import m from '../lib/messages' could be renamed to improve code readability. A more descriptive name like messages or errorMessages would make the code's intent clearer.

Consider applying this change:

-import { m } from '../lib/messages'
+import { m as errorMessages } from '../lib/messages'

Then update all occurrences of m. to errorMessages. in the file.

libs/auth-api-lib/src/lib/delegations/admin/delegation-admin-custom.service.ts (3)

63-66: Improved error handling: LGTM with a suggestion

The updated BadRequestException with a structured error object is a good improvement. It provides more detailed information for error handling on the client side.

Consider extracting the error message to a constant or using a localization key for easier maintenance and potential future localization:

const MISSING_CUSTOM_FIELDS_ERROR = 'Zendesk ticket is missing required custom fields';

throw new BadRequestException({
  message: MISSING_CUSTOM_FIELDS_ERROR,
  error: ErrorCodes.ZENDESK_CUSTOM_FIELDS_MISSING
});

163-168: Consistent error handling improvement: LGTM with a suggestion

The updated BadRequestException instances with structured error objects are a good improvement. They provide more detailed and consistent error information.

For better maintainability and consistency, consider extracting the error messages to constants or using localization keys, similar to the suggestion for the getNationalIdsFromZendeskTicket method. This approach would make it easier to manage and potentially localize error messages in the future.

Example:

const ZENDESK_ERRORS = {
  MISSING_TAG: 'Zendesk case is missing required tag',
  NOT_SOLVED: 'Zendesk case is not solved',
  NATIONAL_IDS_MISMATCH: 'National Ids do not match the Zendesk ticket'
};

// Then use it like this:
throw new BadRequestException({
  message: ZENDESK_ERRORS.MISSING_TAG,
  error: ErrorCodes.ZENDESK_TAG_MISSING
});

Also applies to: 172-177, 188-191


275-278: Consistent error handling in validation: LGTM with a suggestion

The updated BadRequestException instances in the validatePersonsNationalIds method are consistent with the new error handling approach. They provide more detailed and specific error information.

For consistency with the previous suggestions, consider extracting the error messages to constants or using localization keys. This would improve maintainability and make future localization easier if needed.

Example:

const VALIDATION_ERRORS = {
  SAME_NATIONAL_ID: 'National Ids cannot be the same',
  INVALID_PERSON: 'National Ids are not valid'
};

// Usage:
throw new BadRequestException({
  message: VALIDATION_ERRORS.SAME_NATIONAL_ID,
  error: ErrorCodes.INPUT_VALIDATION_SAME_NATIONAL_ID
});

Also applies to: 286-289

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between acd3822 and 38be3af.

📒 Files selected for processing (7)
  • libs/auth-api-lib/src/lib/delegations/admin/delegation-admin-custom.service.ts (6 hunks)
  • libs/portals/admin/delegation-admin/src/constants/errors.ts (1 hunks)
  • libs/portals/admin/delegation-admin/src/lib/messages.ts (1 hunks)
  • libs/portals/admin/delegation-admin/src/screens/CreateDelegation/CreateDelegation.action.ts (3 hunks)
  • libs/portals/admin/delegation-admin/src/screens/CreateDelegation/CreateDelegation.tsx (2 hunks)
  • libs/shared/utils/src/index.ts (1 hunks)
  • libs/shared/utils/src/lib/errorCodes.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • libs/portals/admin/delegation-admin/src/screens/CreateDelegation/CreateDelegation.action.ts
  • libs/portals/admin/delegation-admin/src/screens/CreateDelegation/CreateDelegation.tsx
🧰 Additional context used
📓 Path-based instructions (5)
libs/auth-api-lib/src/lib/delegations/admin/delegation-admin-custom.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/portals/admin/delegation-admin/src/constants/errors.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/portals/admin/delegation-admin/src/lib/messages.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/shared/utils/src/index.ts (2)

Pattern libs/shared/**/*: "Confirm that the code adheres to the following:

  • Cross-application utility functions, types, and constants.
  • TypeScript best practices to ensure type safety and reusability.
  • Documentation and examples for library consumers."

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/shared/utils/src/lib/errorCodes.ts (2)

Pattern libs/shared/**/*: "Confirm that the code adheres to the following:

  • Cross-application utility functions, types, and constants.
  • TypeScript best practices to ensure type safety and reusability.
  • Documentation and examples for library consumers."

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🔇 Additional comments (10)
libs/portals/admin/delegation-admin/src/constants/errors.ts (1)

4-11: LGTM! Well-structured error mapping.

The FORM_ERRORS constant is well-implemented:

  • It uses computed property names with the ErrorCodes enum, ensuring type safety.
  • The mapping covers various error scenarios, providing specific messages for each case.
  • The structure is consistent and easy to maintain.

This approach will make it easier to display relevant error messages in the create form, aligning with the PR's objective.

libs/shared/utils/src/index.ts (1)

26-26: New export added for error codes utility.

The addition of export * from './lib/errorCodes' aligns well with the existing structure of this index file, which exports various utility functions and types. This change enhances the shared utilities by including error codes, which can be beneficial for consistent error handling across the application.

To ensure this addition meets our coding guidelines, let's verify the contents and structure of the errorCodes module:

This script will help us confirm that the errorCodes module adheres to our coding guidelines, including TypeScript best practices, proper exports, and documentation for library consumers.

libs/portals/admin/delegation-admin/src/lib/messages.ts (5)

124-127: LGTM: New error message for national ID mismatch.

The nationalIdsMismatchError message is well-defined and follows the existing pattern in the file. The id is descriptive, and the default message clearly communicates the error condition.


136-139: LGTM: New error message for missing Zendesk custom fields.

The zendeskCustomFieldsMissingError message is well-defined and follows the existing pattern in the file. The id is descriptive, and the default message clearly communicates the error condition.


140-143: LGTM: New error message for identical national IDs.

The sameNationalIdError message is well-defined and follows the existing pattern in the file. The id is descriptive, and the default message clearly communicates the error condition.


144-147: LGTM: New error message for invalid national IDs.

The validPersonError message is well-defined and follows the existing pattern in the file. The id is descriptive, and the default message clearly communicates the error condition.


124-147: Overall assessment: Good additions with minor improvements needed.

The new error messages enhance the user experience by providing more specific feedback, which aligns with the PR objectives. The additions follow the existing patterns in the file and adhere to the coding guidelines for reusability and TypeScript usage.

Please address the typos mentioned in the previous comments. Once these are fixed, the changes will significantly improve error handling in the delegation admin interface.

Regarding the coding guidelines:

  1. Reusability: These message definitions can be easily imported and used across different NextJS apps within the project.
  2. TypeScript usage: The defineMessages function ensures type safety for the message definitions.
  3. Tree-shaking and bundling: The use of named exports allows for effective tree-shaking in the build process.
libs/auth-api-lib/src/lib/delegations/admin/delegation-admin-custom.service.ts (3)

31-31: LGTM: Import of ErrorCodes

The addition of the ErrorCodes import from the shared utils package is appropriate for the new error handling approach. This adheres to the coding guidelines for reusability across different NextJS apps.


Line range hint 1-301: Overall structure and guideline adherence: LGTM

The file structure and the implemented changes adhere well to the coding guidelines:

  1. The code is part of the libs directory and maintains reusability across different NextJS apps.
  2. TypeScript is used effectively throughout the file for type definitions and interfaces.
  3. The changes focus on improving error handling without affecting tree-shaking or bundling practices.

The modifications enhance the error reporting mechanism while maintaining the overall structure and purpose of the service.


Line range hint 1-301: Summary of changes: Improved error handling

The modifications in this file consistently enhance the error handling mechanism across the DelegationAdminCustomService. Key improvements include:

  1. Introduction of structured error objects with specific error codes.
  2. Consistent use of ErrorCodes from a shared utility package.
  3. More detailed and informative error messages.

These changes will significantly improve error identification and handling on the client side, leading to better debugging and user experience. The code maintains good adherence to the project's coding guidelines for reusability, TypeScript usage, and effective tree-shaking.

To further enhance maintainability, consider implementing the suggested extractions of error messages to constants or localization keys.

libs/shared/utils/src/lib/errorCodes.ts Outdated Show resolved Hide resolved
libs/portals/admin/delegation-admin/src/lib/messages.ts Outdated Show resolved Hide resolved
libs/portals/admin/delegation-admin/src/lib/messages.ts Outdated Show resolved Hide resolved
Copy link
Member

@saevarma saevarma left a comment

Choose a reason for hiding this comment

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

🚀

@saevarma saevarma added the automerge Merge this PR as soon as all checks pass label Sep 30, 2024
@kodiakhq kodiakhq bot merged commit efbef76 into main Sep 30, 2024
197 checks passed
@kodiakhq kodiakhq bot deleted the fix/create-delegation-form-errors-message] branch September 30, 2024 14:06
thoreyjona pushed a commit that referenced this pull request Oct 2, 2024
* show propper error messages

* chore: nx format:write update dirty files

* return error message and code, use code to translate error on client

* chore: nx format:write update dirty files

* Fix typos

* Explicitly type FORM_ERRORS

---------

Co-authored-by: andes-it <[email protected]>
Co-authored-by: Sævar Már Atlason <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants