Skip to content
Snippets Groups Projects
Commit 5d569234 authored by Clayton, Brandon Scott's avatar Clayton, Brandon Scott
Browse files

add http interceptor

parent bbedd76f
No related branches found
No related tags found
1 merge request!542Interceptor
......@@ -7,7 +7,7 @@ import {provideRouter} from '@angular/router';
import {AppComponent} from './app/app.component';
import {appRoutes} from './app/app.routes';
import {environment} from './environments/environment';
import {tooManyRequestsInterceptor} from './shared/interceptors/too-many-requests.interceptor';
import {httpErrorInterceptor} from './shared/interceptors/http-error.interceptor';
if (environment.production) {
enableProdMode();
......@@ -18,6 +18,6 @@ bootstrapApplication(AppComponent, {
importProvidersFrom(BrowserModule),
provideRouter(appRoutes()),
provideAnimations(),
provideHttpClient(withInterceptors([tooManyRequestsInterceptor])),
provideHttpClient(withInterceptors([httpErrorInterceptor])),
],
}).catch(err => console.error(err));
......@@ -6,17 +6,14 @@ import {
} from '@angular/common/http';
import {catchError, Observable} from 'rxjs';
export function tooManyRequestsInterceptor(
export function httpErrorInterceptor(
req: HttpRequest<unknown>,
next: HttpHandlerFn
): Observable<HttpEvent<unknown>> {
return next(req).pipe(
catchError(error => {
console.log(error);
if (error instanceof HttpErrorResponse) {
if (typeof error.error === 'string') {
console.log('is string');
throw new Error(error.error);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment