@@ -12,6 +12,7 @@ import { environment } from '../../../environments/environment';
1212/** Custom Services */
1313import { Logger } from '../logger/logger.service' ;
1414import { AlertService } from '../alert/alert.service' ;
15+ import { TranslateService } from '@ngx-translate/core' ; // Added import for TranslateService
1516
1617/** Initialize Logger */
1718const log = new Logger ( 'ErrorHandlerInterceptor' ) ;
@@ -23,20 +24,24 @@ const log = new Logger('ErrorHandlerInterceptor');
2324export class ErrorHandlerInterceptor implements HttpInterceptor {
2425 /**
2526 * @param {AlertService } alertService Alert Service.
27+ * @param {TranslateService } translate Translation Service.
2628 */
27- constructor ( private alertService : AlertService ) { }
29+ constructor (
30+ private alertService : AlertService ,
31+ private translate : TranslateService // Added TranslateService
32+ ) { }
2833
2934 /**
3035 * Intercepts a Http request and adds a default error handler.
3136 */
3237 intercept ( request : HttpRequest < any > , next : HttpHandler ) : Observable < HttpEvent < any > > {
33- return next . handle ( request ) . pipe ( catchError ( ( error ) => this . handleError ( error ) ) ) ;
38+ return next . handle ( request ) . pipe ( catchError ( ( error ) => this . handleError ( error , request ) ) ) ;
3439 }
3540
3641 /**
3742 * Error handler.
3843 */
39- private handleError ( response : HttpErrorResponse ) : Observable < HttpEvent < any > > {
44+ private handleError ( response : HttpErrorResponse , request : HttpRequest < any > ) : Observable < HttpEvent < any > > {
4045 const status = response . status ;
4146 let errorMessage = response . error . developerMessage || response . message ;
4247 if ( response . error . errors ) {
@@ -64,7 +69,17 @@ export class ErrorHandlerInterceptor implements HttpInterceptor {
6469 message : errorMessage || 'You are not authorized for this request!'
6570 } ) ;
6671 } else if ( status === 404 ) {
67- this . alertService . alert ( { type : 'Resource does not exist' , message : errorMessage || 'Resource does not exist!' } ) ;
72+ // Check if this is an image request that should be silently handled (client profile image)
73+ if ( request . url . includes ( '/clients/' ) && request . url . includes ( '/images' ) ) {
74+ // Don't show alerts for missing client images
75+ // This is an expected condition, not an error
76+ return new Observable < HttpEvent < any > > ( ) ;
77+ } else {
78+ this . alertService . alert ( {
79+ type : this . translate . instant ( 'error.resource.not.found' ) ,
80+ message : errorMessage || 'Resource does not exist!'
81+ } ) ;
82+ }
6883 } else if ( status === 500 ) {
6984 this . alertService . alert ( {
7085 type : 'Internal Server Error' ,
0 commit comments