Conversation
…r messages (#34646) The UVE Personalization error handler was only catching and displaying one generic error message ("Personalization requires page content. Add some first"), making it difficult to debug when other errors occurred. Changes: - Added error detail extraction from HttpErrorResponse - Check error-message header first for backend messages - Parse error body to extract meaningful message after colon prefix - Fall back to generic i18n message only when no specific error available - Added 3 comprehensive test cases for different error scenarios This allows users and developers to see actual error messages from the backend, making debugging significantly easier. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR improves error handling for UVE Personalization by extracting and displaying specific backend error messages instead of always showing a generic "Personalization requires page content" message. The implementation adds a new private method to extract error details from HTTP error responses, checking both the error-message header and the response body, with fallback to a localized message when no specific error is available.
Changes:
- Added
#getPersonalizeErrorDetail()method to extract meaningful error messages fromHttpErrorResponseobjects - Enhanced error handler to display backend-specific error messages for better debugging
- Added comprehensive test coverage for error extraction from headers and body
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
dot-uve-toolbar.component.ts |
Added error extraction method and updated error handler to use specific backend messages |
dot-uve-toolbar.component.spec.ts |
Added 3 test cases covering error-message header, body with colon prefix, and body without prefix |
| error: (err: HttpErrorResponse) => { | ||
| const detail = | ||
| this.#getPersonalizeErrorDetail(err) ?? |
There was a problem hiding this comment.
The error parameter is typed as HttpErrorResponse, but RxJS error callbacks can emit any error type. The existing test at line 680 demonstrates this by passing a generic Error object. While the runtime behavior is correct (undefined checks cause it to return null), TypeScript should show a type error when passing non-HttpErrorResponse errors to this handler.
The error parameter on line 241 should be typed as unknown instead of HttpErrorResponse, and then use a type guard to check if it's an HttpErrorResponse before calling #getPersonalizeErrorDetail. For example:
error: (err: unknown) => {
const detail = err instanceof HttpErrorResponse
? this.#getPersonalizeErrorDetail(err)
: null;
const fallback = detail ?? this.#dotMessageService.get('uve.personalize.empty.page.error');
// ... rest of error handling
}This ensures type safety while maintaining backward compatibility with the existing test that passes a generic Error object.
| error: (err: HttpErrorResponse) => { | |
| const detail = | |
| this.#getPersonalizeErrorDetail(err) ?? | |
| error: (err: unknown) => { | |
| const detail = | |
| (err instanceof HttpErrorResponse | |
| ? this.#getPersonalizeErrorDetail(err) | |
| : null) ?? |
| const afterColon = bodyError.indexOf(': '); | ||
| return afterColon >= 0 ? bodyError.slice(afterColon + 2).trim() : bodyError.trim(); |
There was a problem hiding this comment.
If the error body contains only whitespace (e.g., error: { error: " " }), the method will return an empty string after trimming, which will be used as the error message instead of falling back to the i18n message. This would result in displaying an error toast with no message content.
The fix is to check if the trimmed result is empty before returning it:
if (typeof bodyError === 'string') {
const trimmed = bodyError.trim();
if (!trimmed) return null;
const afterColon = trimmed.indexOf(': ');
return afterColon >= 0 ? trimmed.slice(afterColon + 2).trim() : trimmed;
}Or more concisely using the same pattern as the header check:
if (typeof bodyError === 'string') {
const trimmed = bodyError.trim();
if (trimmed) {
const afterColon = trimmed.indexOf(': ');
return afterColon >= 0 ? trimmed.slice(afterColon + 2).trim() : trimmed;
}
}| const afterColon = bodyError.indexOf(': '); | |
| return afterColon >= 0 ? bodyError.slice(afterColon + 2).trim() : bodyError.trim(); | |
| const trimmed = bodyError.trim(); | |
| if (trimmed) { | |
| const afterColon = trimmed.indexOf(': '); | |
| return afterColon >= 0 ? trimmed.slice(afterColon + 2).trim() : trimmed; | |
| } |
Summary
Fixes the UVE Personalization error handling which was only showing one generic error message ("Personalization requires page content. Add some first"), making it extremely difficult to debug when different errors occurred.
Changes
#getPersonalizeErrorDetail()method to extract meaningful error messages fromHttpErrorResponseerror-messageheader for backend messagesnullto use generic i18n message only when no specific error availableerror-messageheaderWhy this matters
Previously, any Personalization creation error would only display "Personalization requires page content. Add some first", regardless of the actual problem. This made debugging:
Nearly impossible to troubleshoot without checking browser console or backend logs.
Example errors now properly shown:
Test plan
Related Issue
Fixes #34646
🤖 Generated with Claude Code