Skip to content

WEB-965: use parsed errorBody consistently in ErrorHandlerInterceptor#3610

Open
RiteshGite wants to merge 1 commit into
openMF:devfrom
RiteshGite:WEB-965-fix-error-handler
Open

WEB-965: use parsed errorBody consistently in ErrorHandlerInterceptor#3610
RiteshGite wants to merge 1 commit into
openMF:devfrom
RiteshGite:WEB-965-fix-error-handler

Conversation

@RiteshGite
Copy link
Copy Markdown

@RiteshGite RiteshGite commented May 24, 2026

Description

Prevents runtime crashes in ErrorHandlerInterceptor when handling malformed or ArrayBuffer-based API error responses.

This change updates the interceptor to consistently use the parsed errorBody instead of directly accessing response.error. It also safely handles nullable error fields using optional chaining and preserves fallback error message behavior.

This fixes cases where the global error handler could fail when:

  • API errors were returned as ArrayBuffer
  • errors[0] was missing
  • defaultUserMessage or developerMessage was null/undefined

Related Issues and Discussion

#WEB-965


Reproduction Steps

To validate the unsafe cases, the interceptor's intercept() method was temporarily modified to force specific error payloads.

Scenario 1: Empty errors array

Temporary code used
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
  return throwError(() =>
    new HttpErrorResponse({
      status: 400,
      url: request.url,
      error: { errors: [] }
    })
  ).pipe(catchError((error) => this.handleError(error, request)));
}

Expected issue before fix: Runtime error when the code tries to access errorBody.errors[0].


Scenario 2: null defaultUserMessage

Temporary code used
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
  return throwError(() =>
    new HttpErrorResponse({
      status: 400,
      url: request.url,
      error: {
        errors: [{
          defaultUserMessage: null,
          developerMessage: "Detailed logs"
        }]
      }
    })
  ).pipe(catchError((error) => this.handleError(error, request)));
}

Expected issue before fix: Runtime error when .replace() is called on null.


Screenshots

1. Empty array crash
EmptyArray.mp4
2. Null value crash
nullError.mp4
3. After fix — error handler working correctly AfterErrorHandlerChange

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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 24, 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: "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

This PR refactors the error-handler interceptor's message-derivation logic to use safer optional chaining on parsed errorBody, improve database-integrity code detection via array includes(), and normalize messages by replacing dots with spaces. The single-file change affects how HTTP error responses map to user-facing error messages.

Changes

Error Handler Message Derivation

Layer / File(s) Summary
Error message extraction and normalization
src/app/core/http/error-handler.interceptor.ts
Lines 95–106 refactor errorMessage derivation from errorBody.errors[0] with safer optional chaining on defaultUserMessage/developerMessage; database-integrity detection now uses includes() to check userMessageGlobalisationCode and translates matching codes to a fixed integrity-issue message; non-integrity paths clean up messages by replacing dots with spaces via regex.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • openMF/web-app#3452: Both PRs modify src/app/core/http/error-handler.interceptor.ts to refine how errorMessage is derived from HTTP error payloads using userMessageGlobalisationCode and errorBody.errors[0].

Suggested reviewers

  • alberto-art3ch
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title 'WEB-965: use parsed errorBody consistently in ErrorHandlerInterceptor' accurately summarizes the main change: using parsed errorBody instead of response.error in the error handler.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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.

@RiteshGite RiteshGite changed the title fix: use parsed errorBody consistently in ErrorHandlerInterceptor WEB-965 use parsed errorBody consistently in ErrorHandlerInterceptor May 24, 2026
@RiteshGite RiteshGite changed the title WEB-965 use parsed errorBody consistently in ErrorHandlerInterceptor WEB-965: use parsed errorBody consistently in ErrorHandlerInterceptor May 24, 2026
Copy link
Copy Markdown
Contributor

@IOhacker IOhacker left a comment

Choose a reason for hiding this comment

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

Could you please add an evidence of the change?

Copy link
Copy Markdown
Collaborator

@alberto-art3ch alberto-art3ch left a comment

Choose a reason for hiding this comment

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

LGTM

@RiteshGite
Copy link
Copy Markdown
Author

@IOhacker Added evidence for the reported issue along with before/after screenshots. Please review again. Thanks!

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.

3 participants