Skip to content

WEB-933: Fix null dereference in ErrorHandlerInterceptor when default…#3532

Open
adity-a34 wants to merge 1 commit intoopenMF:devfrom
adity-a34:WEB-933-fix-error-handler-null-default-user-message
Open

WEB-933: Fix null dereference in ErrorHandlerInterceptor when default…#3532
adity-a34 wants to merge 1 commit intoopenMF:devfrom
adity-a34:WEB-933-fix-error-handler-null-default-user-message

Conversation

@adity-a34
Copy link
Copy Markdown
Contributor

@adity-a34 adity-a34 commented Apr 26, 2026

Description

Guards against a null dereference crash in ErrorHandlerInterceptor. Fineract APIs can return defaultUserMessage as null on constraint violations. The error handler accessed .replace() directly on that null value, crashing before the developerMessage fallback could run.
This silently broke error reporting across the entire app for any API response where defaultUserMessage is null.

Also switches from response.error.errors to the already-decoded errorBody (which parseErrorBody produces) for consistent binary response handling, and extracts firstError to eliminate repeated deep-chain access.

Jira: https://mifosforge.jira.com/browse/WEB-933

Related issues and discussion

No existing issue. Ticket created: WEB-933.

Screenshots, if any

Before: Cannot read properties of null (reading 'replace')

Screenshot 2026-04-26 115239

After: Result: Some dev message

Screenshot 2026-04-26 121847

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 robustness of nested error parsing to reliably extract and display the most relevant error message.
    • Enhanced fallback selection for user-facing messages when database error codes don't match.
    • Corrected extraction of parameter names for clearer error context and ensured consistent formatting of message punctuation.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 26, 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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 04fa9a46-bf6b-429b-ad1a-843ce9eb41a9

📥 Commits

Reviewing files that changed from the base of the PR and between c8f48c7 and fa26b97.

📒 Files selected for processing (1)
  • src/app/core/http/error-handler.interceptor.ts

Walkthrough

Switches nested error extraction in the HTTP error handler to use the parsed errorBody?.errors?.[0] (assigned to firstError) for message, code, and parameter lookups; updates fallback message selection with optional chaining and adjusts dot-replacement regex usage.

Changes

Cohort / File(s) Summary
Error Handler Refactor
src/app/core/http/error-handler.interceptor.ts
Use errorBody?.errors?.[0] as firstError for nested error reads (userMessageGlobalisationCode, defaultUserMessage, developerMessage, parameterName); apply optional chaining for fallbacks and keep dot-to-space replacement via /\./g.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • alberto-art3ch
  • IOhacker
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main change: fixing null dereference in ErrorHandlerInterceptor when defaultUserMessage is null.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
src/app/core/http/error-handler.interceptor.ts (1)

79-82: Optional: reuse firstError for the other errorBody.errors[0] accesses.

Since firstError is already pulled out at line 96 to avoid repeated deep-chain access, the same alias could be hoisted above the nested-globalisation block (line 79) and reused at line 123 for consistency and slightly better readability. Not required for this fix.

♻️ Sketch
+    const firstError = errorBody?.errors?.[0];
+
     // Translate nested globalisation code if present
     let nestedMessage: string | null = null;
-    if (errorBody?.errors?.[0]?.userMessageGlobalisationCode) {
-      const nestedCode = errorBody.errors[0].userMessageGlobalisationCode;
-      const translated = this.translate.instant(nestedCode, errorBody.errors[0] || {});
-      nestedMessage = translated !== nestedCode ? translated : errorBody.errors[0].defaultUserMessage || null;
+    if (firstError?.userMessageGlobalisationCode) {
+      const nestedCode = firstError.userMessageGlobalisationCode;
+      const translated = this.translate.instant(nestedCode, firstError || {});
+      nestedMessage = translated !== nestedCode ? translated : firstError.defaultUserMessage || null;
     }
@@
-    if (errorBody?.errors?.[0]) {
-      const firstError = errorBody.errors[0];
+    if (firstError) {
@@
-      status === 403 &&
-      errorBody?.errors?.[0]?.defaultUserMessage === 'The provided one time token is invalid'
+      status === 403 &&
+      firstError?.defaultUserMessage === 'The provided one time token is invalid'

Also applies to: 121-124

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

In `@src/app/core/http/error-handler.interceptor.ts` around lines 79 - 82,
Rename/hoist the local alias for errorBody.errors[0] to a single variable (e.g.,
firstError) before the nested-globalisation block and use it everywhere instead
of repeating errorBody.errors[0]; update the checks that reference
userMessageGlobalisationCode, translate.instant, nestedMessage assignment, and
the later block that reads defaultUserMessage to use firstError so all deep
accesses are consistent (references: errorBody, firstError,
userMessageGlobalisationCode, translate.instant, nestedMessage,
defaultUserMessage).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/app/core/http/error-handler.interceptor.ts`:
- Around line 79-82: Rename/hoist the local alias for errorBody.errors[0] to a
single variable (e.g., firstError) before the nested-globalisation block and use
it everywhere instead of repeating errorBody.errors[0]; update the checks that
reference userMessageGlobalisationCode, translate.instant, nestedMessage
assignment, and the later block that reads defaultUserMessage to use firstError
so all deep accesses are consistent (references: errorBody, firstError,
userMessageGlobalisationCode, translate.instant, nestedMessage,
defaultUserMessage).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a0ecfac5-21a8-4222-b902-2cd772d68c8c

📥 Commits

Reviewing files that changed from the base of the PR and between 2a6f1e3 and c8f48c7.

📒 Files selected for processing (1)
  • src/app/core/http/error-handler.interceptor.ts

@adity-a34 adity-a34 force-pushed the WEB-933-fix-error-handler-null-default-user-message branch from c8f48c7 to fa26b97 Compare April 26, 2026 08:01
@adity-a34
Copy link
Copy Markdown
Contributor Author

Hi @IOhacker, I have fixed the CI issues from the last commit,
It is ready for review!

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