From 2cf5cf2fc4c07a5a2a274c5857dcc54fde1b6821 Mon Sep 17 00:00:00 2001 From: tkshsbcue Date: Mon, 9 Mar 2026 10:08:27 +0530 Subject: [PATCH 1/2] WEB-826: Improve null-safety in ErrorHandlerInterceptor Safely access response.error with optional chaining; honor root error.defaultUserMessage before developerMessage. Handles network errors and non-JSON responses without crashing. Made-with: Cursor --- src/app/core/http/error-handler.interceptor.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/app/core/http/error-handler.interceptor.ts b/src/app/core/http/error-handler.interceptor.ts index 9aec7fd20d..7eb95b3d4f 100644 --- a/src/app/core/http/error-handler.interceptor.ts +++ b/src/app/core/http/error-handler.interceptor.ts @@ -45,11 +45,10 @@ export class ErrorHandlerInterceptor implements HttpInterceptor { */ private handleError(response: HttpErrorResponse, request: HttpRequest): Observable> { const status = response.status; - let errorMessage = response.error.developerMessage || response.message; - if (response.error.errors) { - if (response.error.errors[0]) { - errorMessage = response.error.errors[0].defaultUserMessage || response.error.errors[0].developerMessage; - } + const error = response?.error; + let errorMessage = error?.defaultUserMessage || error?.developerMessage || response?.message || 'Unknown error'; + if (error?.errors?.[0]) { + errorMessage = error.errors[0].defaultUserMessage || error.errors[0].developerMessage || errorMessage; } const isClientImage404 = status === 404 && request.url.includes('/clients/') && request.url.includes('/images'); From 81ea93545047dc2a401283d41e5599f9d0df19ae Mon Sep 17 00:00:00 2001 From: tkshsbcue Date: Tue, 10 Mar 2026 07:50:14 +0530 Subject: [PATCH 2/2] WEB-826: Use only backend fields for user-facing errorMessage Remove response?.message from user-facing chain; keep transport string for logging only (logMessage). Made-with: Cursor --- src/app/core/http/error-handler.interceptor.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/core/http/error-handler.interceptor.ts b/src/app/core/http/error-handler.interceptor.ts index 7eb95b3d4f..2ca401dc5b 100644 --- a/src/app/core/http/error-handler.interceptor.ts +++ b/src/app/core/http/error-handler.interceptor.ts @@ -46,7 +46,7 @@ export class ErrorHandlerInterceptor implements HttpInterceptor { private handleError(response: HttpErrorResponse, request: HttpRequest): Observable> { const status = response.status; const error = response?.error; - let errorMessage = error?.defaultUserMessage || error?.developerMessage || response?.message || 'Unknown error'; + let errorMessage = error?.defaultUserMessage || error?.developerMessage || 'Unknown error'; if (error?.errors?.[0]) { errorMessage = error.errors[0].defaultUserMessage || error.errors[0].developerMessage || errorMessage; } @@ -54,7 +54,8 @@ export class ErrorHandlerInterceptor implements HttpInterceptor { const isClientImage404 = status === 404 && request.url.includes('/clients/') && request.url.includes('/images'); if (!environment.production && !isClientImage404) { - log.error(`Request Error: ${errorMessage}`); + const logMessage = response?.message || errorMessage; + log.error(`Request Error: ${logMessage}`); } if (status === 401 || (environment.oauth.enabled && status === 400)) {