Skip to content

WEB-862: Handle API errors using userMessageGlobalisationCode with lo…#3411

Open
samruddhikasar05-bit wants to merge 1 commit intoopenMF:devfrom
samruddhikasar05-bit:WEB-862-error-localisation
Open

WEB-862: Handle API errors using userMessageGlobalisationCode with lo…#3411
samruddhikasar05-bit wants to merge 1 commit intoopenMF:devfrom
samruddhikasar05-bit:WEB-862-error-localisation

Conversation

@samruddhikasar05-bit
Copy link

@samruddhikasar05-bit samruddhikasar05-bit commented Mar 19, 2026

…calisation

Description

Describe the changes made and why they were made instead of how they were made. List any dependencies that are required for this change.

Related issues and discussion

#{Issue Number}

Screenshots, if any

Checklist

Please make sure these boxes are checked before submitting your pull request - thanks!

  • If you have multiple commits please combine them into one commit by squashing them.

  • Read and understood the contribution guidelines at web-app/.github/CONTRIBUTING.md.

Summary by CodeRabbit

  • Bug Fixes
    • Improved error messaging when loans data fails to load. Users now receive localized error messages to help identify and resolve issues.

@coderabbitai
Copy link

coderabbitai bot commented Mar 19, 2026

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key(s) in object: 'pre_merge_checks'
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • 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

Walkthrough

The change modifies error handling in LoansViewComponent.filterDatatablesByProduct() to extract, translate, and display error messages to the user via alert, replacing the previous silent error handling that only set datatablesReady = true.

Changes

Cohort / File(s) Summary
Error Handler Enhancement
src/app/loans/loans-view/loans-view.component.ts
Updated getEntityDataTableChecks() error callback to extract error details from err.error?.errors, translate each entry's userMessageGlobalisationCode, concatenate messages with spaces, and display via alert() instead of silently failing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • IOhacker
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding API error handling using userMessageGlobalisationCode with localization.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can enforce grammar and style rules using `languagetool`.

Configure the reviews.tools.languagetool setting to enable/disable rules and categories. Refer to the LanguageTool Community to learn more.

Copy link

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/app/loans/loans-view/loans-view.component.ts`:
- Line 253: Replace the raw browser alert call at the end of the handler with
the app's alertService pattern: remove alert(message) in loans-view.component
(the method where alert(message) is invoked) and call this.alertService.alert({
type: '<appropriate-type>', message }) instead, matching how
transactions-tab.component.ts and view-transaction.component.ts use
this.alertService; ensure the component has alertService injected in the
constructor if not already.
- Around line 249-251: Replace the incorrect reference this.translate.instant
with the injected translateService (this.translateService.instant) and ensure
translateService is defined on the component (constructor injection already
present as translateService); when building the message from errors use a
fallback chain: prefer error.userMessageGlobalisationCode (translated),
otherwise error.defaultUserMessage, otherwise error.developerMessage, and
finally a generic text; and replace the native alert() call with the app's
notification service (e.g., this.notificationService.error or similar) to
display the assembled message so the UI uses the proper notifier.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 66547569-fb36-4ae1-a7f7-3a5dbfeb41fa

📥 Commits

Reviewing files that changed from the base of the PR and between d4fa504 and 7a6cecc.

📒 Files selected for processing (1)
  • src/app/loans/loans-view/loans-view.component.ts

Comment on lines +249 to +251
const message = errors
.map(e => this.translate.instant(e.userMessageGlobalisationCode))
.join(' ');
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify incorrect member usage and compare expected error fields.
rg -nP 'private\s+translate(Service)?\s*=' src/app/loans/loans-view/loans-view.component.ts
rg -nP '\bthis\.translate\.instant\s*\(' src/app/loans/loans-view/loans-view.component.ts
rg -nP 'defaultUserMessage|developerMessage|userMessageGlobalisationCode' src/app/core/http/error-handler.interceptor.ts src/app/loans/loans-view/loans-view.component.ts

Repository: openMF/web-app

Length of output: 605


🏁 Script executed:

# Read the full code section around lines 243-255 to see alert() and complete logic
head -n 255 src/app/loans/loans-view/loans-view.component.ts | tail -n 20

Repository: openMF/web-app

Length of output: 580


🏁 Script executed:

# Also check for other uses of translate service in this file
rg -n 'this\.(translate|translateService)\.' src/app/loans/loans-view/loans-view.component.ts

Repository: openMF/web-app

Length of output: 563


🏁 Script executed:

# Verify the error response structure more thoroughly
cat -n src/app/core/http/error-handler.interceptor.ts | head -n 60 | tail -n 20

Repository: openMF/web-app

Length of output: 885


Fix undeclared translate service reference and add error message fallback with proper notification.

Line 250 uses this.translate.instant(...), but the component declares this.translateService (Line 83). This reference will fail type-checking. Additionally, line 253 uses native alert() instead of a notification service, and the error mapping lacks fallback for defaultUserMessage or developerMessage when userMessageGlobalisationCode is missing.

Proposed fix
    const message = errors
-      .map(e => this.translate.instant(e.userMessageGlobalisationCode))
+      .map((e: { userMessageGlobalisationCode?: string; defaultUserMessage?: string; developerMessage?: string }) => {
+        const key = e.userMessageGlobalisationCode;
+        return key
+          ? this.translateService.instant(key)
+          : (e.defaultUserMessage ?? e.developerMessage ?? '');
+      })
+      .filter(Boolean)
       .join(' ');
-    alert(message);
+    // Use notification service instead of native alert
+    // this.notificationService.showError(message);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/app/loans/loans-view/loans-view.component.ts` around lines 249 - 251,
Replace the incorrect reference this.translate.instant with the injected
translateService (this.translateService.instant) and ensure translateService is
defined on the component (constructor injection already present as
translateService); when building the message from errors use a fallback chain:
prefer error.userMessageGlobalisationCode (translated), otherwise
error.defaultUserMessage, otherwise error.developerMessage, and finally a
generic text; and replace the native alert() call with the app's notification
service (e.g., this.notificationService.error or similar) to display the
assembled message so the UI uses the proper notifier.

.map(e => this.translate.instant(e.userMessageGlobalisationCode))
.join(' ');

alert(message); // or notification service if exists
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check for native alerts and existing app-level alert patterns to align this call.
rg -nP '\balert\s*\(' src/app --type=ts
rg -nP 'alertService\.alert|MatSnackBar|MatDialog' src/app/loans src/app/shared --type=ts

Repository: openMF/web-app

Length of output: 30334


Replace native alert() with the app's alertService notification pattern.

Line 253 uses browser alert(), which is blocking and inconsistent with the established pattern in the loans module. Other components in this module use this.alertService.alert({ type: '...', message: ... }) (see sibling components like transactions-tab.component.ts and view-transaction.component.ts). Replace the native alert with the app's alertService for consistent UX behavior.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/app/loans/loans-view/loans-view.component.ts` at line 253, Replace the
raw browser alert call at the end of the handler with the app's alertService
pattern: remove alert(message) in loans-view.component (the method where
alert(message) is invoked) and call this.alertService.alert({ type:
'<appropriate-type>', message }) instead, matching how
transactions-tab.component.ts and view-transaction.component.ts use
this.alertService; ensure the component has alertService injected in the
constructor if not already.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant