Skip to content

Commit b028c09

Browse files
committed
🚚 rename error class interceptor name
1 parent f2e7dd8 commit b028c09

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/app/app.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { ROOT_REDUCERS } from './core/store/app.store';
2525
import { AuthInterceptor } from './modules/authentication/interceptors/auth.interceptor';
2626
import { HttpLoadingInterceptor } from './shared/interceptors/http-loading.interceptor';
2727
import { AuthenticationModule } from './modules/authentication/authentication.module';
28-
import { ErrorInterceptor } from './shared/interceptors/error.interceptor';
28+
import { ErrorsInterceptor } from './shared/interceptors/errors.interceptor';
2929

3030
registerLocaleData(localeFr);
3131

@@ -72,7 +72,7 @@ registerLocaleData(localeFr);
7272
},
7373
{
7474
provide: HTTP_INTERCEPTORS,
75-
useClass: ErrorInterceptor,
75+
useClass: ErrorsInterceptor,
7676
multi: true,
7777
},
7878
{

src/app/shared/interceptors/error.interceptor.ts renamed to src/app/shared/interceptors/errors.interceptor.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,37 @@ import {
44
HttpHandler,
55
HttpEvent,
66
HttpInterceptor,
7+
HttpErrorResponse,
78
} from '@angular/common/http';
8-
import { Observable, throwError } from 'rxjs';
9+
import { Observable, of } from 'rxjs';
910
import { catchError } from 'rxjs/operators';
10-
1111
import { Store } from '@ngrx/store';
12+
1213
import { logoutAction } from '@app/modules/authentication/store/auth.actions';
14+
import { fetchFormsErrorAction } from '@app/core/store/session/session.actions';
1315

1416
@Injectable()
15-
export class ErrorInterceptor implements HttpInterceptor {
17+
export class ErrorsInterceptor implements HttpInterceptor {
1618
constructor(private store: Store) {}
1719

1820
intercept(
1921
request: HttpRequest<unknown>,
2022
next: HttpHandler
2123
): Observable<HttpEvent<unknown>> {
2224
return next.handle(request).pipe(
23-
catchError(err => {
24-
if ([401, 403].indexOf(err.status) !== -1) {
25+
catchError((response: HttpErrorResponse) => {
26+
if ([401, 403].includes(response.status)) {
2527
this.store.dispatch(logoutAction());
2628
}
2729

28-
const error = err.error.message || err.statusText;
29-
return throwError(error);
30+
if ([422].includes(response.status)) {
31+
this.store.dispatch(
32+
fetchFormsErrorAction({ formErrors: response.error })
33+
);
34+
}
35+
36+
const error = response.error.message || response.statusText;
37+
return of(error);
3038
})
3139
);
3240
}

0 commit comments

Comments
 (0)