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(my-pages): Law and Order - error handling #16506

Merged
merged 7 commits into from
Oct 23, 2024
Merged

Conversation

disaerna
Copy link
Member

@disaerna disaerna commented Oct 22, 2024

My pages

What

  • Remove button in defender choice form if error
  • Add audit log and error handling if get lawyer calls fails
  • Add more logging

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 in the DefenderChoices component, ensuring buttons only display when there are no errors.
    • Default choice set to "delay" if no choice is provided in the form.
    • Toast notifications added to inform users of mutation errors.
    • Added urgency status to documents in retrieval methods, improving visibility of urgent documents.
  • Bug Fixes

    • Improved control flow for form submission and button states based on loading and error conditions.
    • Enhanced error messaging in the Subpoena component for better user context.

@disaerna disaerna requested a review from a team as a code owner October 22, 2024 11:42
Copy link
Contributor

coderabbitai bot commented Oct 22, 2024

Walkthrough

The pull request introduces enhancements to the LawAndOrderResolver class's getLawyers method, integrating error handling and auditing through the auditAndHandle method. This aligns it with existing methods in the resolver. Additionally, changes to the DefenderChoices component include improved error handling and conditional rendering of UI elements based on error states. Modifications in the DocumentServiceV2 enhance logging and document retrieval functionality, while the Subpoena component improves error message display.

Changes

File Change Summary
libs/api/domains/law-and-order/src/lib/law-and-order.resolver.ts Updated getLawyers method to utilize auditAndHandle for error handling and auditing.
libs/service-portal/law-and-order/src/components/DefenderChoices/DefenderChoices.tsx Added error handling logic to conditionally render UI elements and manage form submission states.
libs/api/domains/documents/src/lib/documentV2.service.ts Enhanced findDocumentByIdV3 and listDocumentsV3 methods with new parameters and logging.
libs/clients/documents-v2/src/lib/documentsClientV2.service.ts Added logging in getCustomersDocument method for document content availability.
libs/service-portal/law-and-order/src/screens/Subpoena/Subpoena.tsx Updated Problem component rendering to include a message prop for better error context.

Possibly related PRs

Suggested reviewers

  • thorkellmani
  • oddsson

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.

@disaerna disaerna changed the title fix(my-pages): error handling fix(my-pages): Law and Order - error handling Oct 22, 2024
@disaerna disaerna added the automerge Merge this PR as soon as all checks pass label Oct 22, 2024
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 (3)
libs/api/domains/law-and-order/src/lib/law-and-order.resolver.ts (1)

98-103: Consider adding a comment for the auditAndHandle method

While the changes adhere to the coding guidelines for files in the libs/**/* path, it would be beneficial to add a brief comment explaining the purpose and functionality of the auditAndHandle method. This would enhance code readability and maintainability, especially for developers who might be new to the project.

For example:

// Wraps the service call with error handling and auditing capabilities
return this.auditAndHandle(
  'getLawyers',
  'lawyers',
  this.lawAndOrderService.getLawyers(user, locale),
  user,
)
libs/service-portal/law-and-order/src/components/DefenderChoices/DefenderChoices.tsx (2)

Line range hint 189-204: Approve changes with a minor suggestion for consistency

The addition of the error check in the conditional rendering of the submit button for non-popup scenarios is a good improvement. It enhances the user experience by preventing form submission when there's an error, which aligns with the PR's objective of improving error handling.

For consistency with the popup scenario, consider extracting the button content into a separate component or variable. This would reduce code duplication and improve maintainability. For example:

const submitButtonContent = postActionLoading ? (
  <LoadingDots />
) : (
  formatMessage(messages.confirm)
);

// Then use it in both popup and non-popup scenarios
<Button
  type="submit"
  size="small"
  disabled={methods.formState.isSubmitting || postActionLoading}
>
  {submitButtonContent}
</Button>

Line range hint 204-235: Approve changes with a suggestion for accessibility improvement

The addition of the error check in the conditional rendering of the submit and cancel buttons for popup scenarios is a good improvement. It enhances the user experience by preventing form submission and cancellation when there's an error, which aligns with the PR's objective of improving error handling.

The use of Box components for layout promotes reusability across different NextJS apps, adhering to the coding guidelines.

To improve accessibility, consider adding aria labels to the buttons. This will help screen readers provide more context to users. For example:

<Button
  type="button"
  size="small"
  variant="ghost"
  onClick={() => popUp.setPopUp(false)}
  aria-label={formatMessage(messages.cancelAriaLabel)} // Add this line
>
  {formatMessage(messages.cancel)}
</Button>

<Button
  type="submit"
  size="small"
  disabled={methods.formState.isSubmitting || postActionLoading}
  aria-label={formatMessage(messages.confirmAriaLabel)} // Add this line
>
  {postActionLoading ? <LoadingDots /> : formatMessage(messages.confirm)}
</Button>

Don't forget to add the corresponding messages to your localization file.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c6b8f91 and 95a594e.

📒 Files selected for processing (2)
  • libs/api/domains/law-and-order/src/lib/law-and-order.resolver.ts (1 hunks)
  • libs/service-portal/law-and-order/src/components/DefenderChoices/DefenderChoices.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
libs/api/domains/law-and-order/src/lib/law-and-order.resolver.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/service-portal/law-and-order/src/components/DefenderChoices/DefenderChoices.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 (1)
libs/api/domains/law-and-order/src/lib/law-and-order.resolver.ts (1)

98-103: Excellent improvement in error handling and auditing!

The changes to the getLawyers method align it with other query methods in the class by utilizing the auditAndHandle method. This enhancement improves error handling and adds auditing capabilities, which is a positive step towards more robust and maintainable code.

The implementation adheres to TypeScript usage and doesn't affect the reusability of the component across different NextJS apps. Good job on maintaining consistency and improving the overall quality of the code.

Copy link

codecov bot commented Oct 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.75%. Comparing base (4919948) to head (1983cd6).
Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16506      +/-   ##
==========================================
- Coverage   36.76%   36.75%   -0.01%     
==========================================
  Files        6851     6850       -1     
  Lines      142120   141935     -185     
  Branches    40542    40471      -71     
==========================================
- Hits        52250    52170      -80     
+ Misses      89870    89765     -105     
Flag Coverage Δ
api 3.37% <ø> (ø)

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

see 25 files with indirect coverage changes


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 f2f1f12...1983cd6. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Oct 22, 2024

Datadog Report

All test runs 8858191 🔗

2 Total Test Services: 0 Failed, 2 Passed
➡️ Test Sessions change in coverage: 9 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 3.02s 1 no change Link
portals-admin-ids-admin 0 0 0 2 0 8.42s 1 no change Link

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: 1

🧹 Outside diff range and nitpick comments (3)
libs/clients/documents-v2/src/lib/documentsClientV2.service.ts (1)

101-106: LGTM! Consider minor improvements to logging.

The added info log complements the existing warning log well and improves observability.

Some minor suggestions to enhance the logging:

  1. Consider a more descriptive message: 'Successfully retrieved document content for findDocumentById'
  2. Consider standardizing the 'No provider available' fallback across all logs
  3. Consider defining LOG_CATEGORY as a const enum for better type safety
-      this.logger.info('Document content available for findDocumentById', {
+      this.logger.info('Successfully retrieved document content for findDocumentById', {
         category: LOG_CATEGORY,
         documentId,
         documentProvider: document?.senderName ?? 'No provider available',
       })
libs/api/domains/documents/src/lib/documentV2.service.ts (2)

131-136: Enhance urgent document logging with additional context

While the current logging is good, consider adding more context to aid in debugging and monitoring:

     if (document.urgent)
       this.logger.info('Urgent document fetched', {
         documentId: documentId,
         includeDocument,
+        category: LOG_CATEGORY,
+        senderName: document.senderName,
+        documentType: document.fileType
       })

493-493: Optimize action mapper success logging

The success logging is good for traceability, but consider optimizing the logged data:

-    this.logger.info('Actions mapped successfully', { actions: mapped })
+    this.logger.info('Actions mapped successfully', {
+      category: LOG_CATEGORY,
+      id,
+      actionCount: mapped.length,
+      actionTypes: mapped.map(action => action.type)
+    })

This change:

  1. Adds consistent category logging
  2. Includes document ID for context
  3. Reduces log verbosity while maintaining useful information

Also applies to: 520-521

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 95a594e and 2425c72.

📒 Files selected for processing (3)
  • libs/api/domains/documents/src/lib/documentV2.service.ts (3 hunks)
  • libs/clients/documents-v2/src/lib/documentsClientV2.service.ts (1 hunks)
  • libs/service-portal/law-and-order/src/screens/Subpoena/Subpoena.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
libs/api/domains/documents/src/lib/documentV2.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/clients/documents-v2/src/lib/documentsClientV2.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/service-portal/law-and-order/src/screens/Subpoena/Subpoena.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 (1)
libs/service-portal/law-and-order/src/screens/Subpoena/Subpoena.tsx (1)

Line range hint 1-190: Implementation follows best practices and guidelines.

The code demonstrates good adherence to the coding guidelines for library code:

  • Properly uses TypeScript for type safety
  • Leverages reusable components from shared libraries
  • Follows effective tree-shaking practices with specific imports
  • Maintains component reusability across NextJS apps

@thorkellmani thorkellmani removed the automerge Merge this PR as soon as all checks pass label Oct 23, 2024
Copy link
Member

@thorkellmani thorkellmani left a comment

Choose a reason for hiding this comment

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

just the coderabbit comment

@disaerna disaerna added the automerge Merge this PR as soon as all checks pass label Oct 23, 2024
@kodiakhq kodiakhq bot merged commit 88c085f into main Oct 23, 2024
36 checks passed
@kodiakhq kodiakhq bot deleted the my-pages/error-testing branch October 23, 2024 18:14
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.

2 participants