WEB-933: Fix null dereference in ErrorHandlerInterceptor when default…#3532
WEB-933: Fix null dereference in ErrorHandlerInterceptor when default…#3532adity-a34 wants to merge 1 commit intoopenMF:devfrom
Conversation
|
Note
|
| 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
- [WEB-820] Display the userMessageGlobalisationCode error in the modal/popup that is displayed on the top right corner #3509: Modifies the same interceptor to read nested error fields from a parsed
errorBody.errors[0]. - fix: WEB-860 Present Globalisation Code translated to local languages … #3452: Changes nested error parsing and access to
userMessageGlobalisationCode/fallback messages in the same file.
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.
Comment @coderabbitai help to get the list of available commands and usage tips.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/app/core/http/error-handler.interceptor.ts (1)
79-82: Optional: reusefirstErrorfor the othererrorBody.errors[0]accesses.Since
firstErroris 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
📒 Files selected for processing (1)
src/app/core/http/error-handler.interceptor.ts
…UserMessage is null
c8f48c7 to
fa26b97
Compare
|
Hi @IOhacker, I have fixed the CI issues from the last commit, |
Description
Guards against a null dereference crash in
ErrorHandlerInterceptor. Fineract APIs can returndefaultUserMessageasnullon constraint violations. The error handler accessed.replace()directly on that null value, crashing before thedeveloperMessagefallback could run.This silently broke error reporting across the entire app for any API response where
defaultUserMessageis null.Also switches from
response.error.errorsto the already-decodederrorBody(whichparseErrorBodyproduces) for consistent binary response handling, and extractsfirstErrorto 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')
After: Result: Some dev message
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