angular-http-interceptors

Angular 5 HttpInterceptor and sending Authorization Token in header

﹥>﹥吖頭↗ 提交于 2020-01-21 08:53:25
问题 My flow is login page -> home page. Login page has no token, after logging in, server provides token and user is redirected to home page. Home page sends the token to server, token is verified, server sends back data to display on front end. Problem: HttpInterceptor firing on login request Cannot read property 'token' of null . I would like to have the interceptor somehow ignore the login api request and only intercept on subsequent calls if token exists. 回答1: hello you can a key value in

Angular httpClient interceptor error handling

痞子三分冷 提交于 2020-01-21 04:52:05
问题 after reading the documentation on angular about http client error handling, I still don't understand why I don't catch a 401 error from the server with the code below: export class interceptor implements HttpInterceptor { intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { console.log('this log is printed on the console!'); return next.handle(request).do(() => (err: any) => { console.log('this log isn't'); if (err instanceof HttpErrorResponse) { if (err

Angular 4.3 - HTTP Interceptor - refresh JWT token

有些话、适合烂在心里 提交于 2020-01-20 19:39:53
问题 I need to react (in interceptor class) on 403 Forbidden HTTP status (to obtain/refresh) JWT token and retry the request with fresh token. In the code below, when server return error response it goes to success callback (not into the error callback as I expect) and the event is typeof object (which is useless in reaction on error response). The event object looks like this: {type:0}. Question: -How to properly handle httpErrorResponse (403 Forbidden) in HttpInterceptor when I need refresh

how does Angular HttpInterceptor get called?

China☆狼群 提交于 2020-01-15 10:11:26
问题 I'm trying to understand some code here: transfer_http.ts I'm trying to understand how it invalidates the cache: // Stop using the cache if there is a mutating call. if (req.method !== 'GET' && req.method !== 'HEAD') { this.isCacheActive = false; this.invalidateCacheEntry(req.url); } How do you get a situation when req.method !== 'GET'? I only use GET requests. 来源: https://stackoverflow.com/questions/55213396/how-does-angular-httpinterceptor-get-called

HttpInterceptor change response body based on value from other observable

杀马特。学长 韩版系。学妹 提交于 2020-01-14 03:39:08
问题 Some how i can't seem to change the response body based on the value from another observable which i can only get after i retrieved the response. Changing the request is pretty simple, i don't know how to do it with the response. @Injectable() export class MyHttpInterceptor implements HttpInterceptor { constructor(private _injector: Injector) { } intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { return next.handle(request).map((event: HttpEvent<any>) => {

Angular 2 login not working in safari and firefox

谁都会走 提交于 2020-01-06 07:05:34
问题 For some reason the login part of my application is not working on safari and firefox. I get this error while trying to auth. Now the code is working perfectly in chrome. Signin Service.ts import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { Http, Headers, RequestOptions } from '@angular/http'; import { HttpWrapper } from '../../../shared/services/http-wrapper.service'; import { SERVER_URL } from '../../../shared/config/config'; import 'rxjs/add

How to handle unauthorized requests(status with 401 or 403) with new httpClient in angular 4.3

血红的双手。 提交于 2019-12-31 15:51:56
问题 I have an auth-interceptor.service.ts to handle the requests import {Injectable} from '@angular/core'; import {HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http'; import {Observable} from 'rxjs/Observable'; import {Cookie} from './cookie.service'; import {Router} from '@angular/router'; @Injectable() export class AuthInterceptor implements HttpInterceptor { constructor(private router: Router) {} intercept(req: HttpRequest<any>, next:

How to make an angular module to ignore http interceptor added in a core module

馋奶兔 提交于 2019-12-27 17:05:50
问题 I do have a core module with an HttpInterceptor for authorization handling and I include this module in AppModule, in this way all the other modules that use HttpClient are using this interceptor. @NgModule({ imports: [], declarations: [], providers: [ { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true, }, ] }) export class CoreModule { } How to make a module bypass the default interceptor? @NgModule({ imports: [ CommonModule ], declarations: components, providers:

How to make an angular module to ignore http interceptor added in a core module

余生颓废 提交于 2019-12-27 17:05:09
问题 I do have a core module with an HttpInterceptor for authorization handling and I include this module in AppModule, in this way all the other modules that use HttpClient are using this interceptor. @NgModule({ imports: [], declarations: [], providers: [ { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true, }, ] }) export class CoreModule { } How to make a module bypass the default interceptor? @NgModule({ imports: [ CommonModule ], declarations: components, providers:

HTTP_INTERCEPTORS only in AppModule

泄露秘密 提交于 2019-12-25 01:34:06
问题 I am trying to implement lazy loading in my Angular 6 app, all of my http calls are made in the FeatureModule (lazy loaded), but still I have to add HttpClientModule in my AppModule and not in FeatureModule . Didn't really understand why. Also, when I added interceptors in my FeatureModule , they didn't intercept any request. I have to add it in the AppModule only (I guess, it is because HttpClientModule is in AppModule ). I want to understand why this is the case?? Why can't we have