Import des sources angular à partir de 'headup_app'
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import { HttpInterceptorFn } from "@angular/common/http";
|
||||
|
||||
import { environment } from 'src/environments/environment';
|
||||
|
||||
export const apiInterceptor: HttpInterceptorFn = (req, next) => {
|
||||
const apiReq = req.clone({
|
||||
setHeaders: {
|
||||
...({ 'Content-Type': 'application/json', 'Accept': 'application/json' }),
|
||||
},
|
||||
url: `${environment.api_url}${req.url}`
|
||||
});
|
||||
return next(apiReq);
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
import { HttpInterceptorFn } from "@angular/common/http";
|
||||
import { throwError } from "rxjs";
|
||||
import { catchError } from "rxjs/operators";
|
||||
|
||||
export const errorInterceptor: HttpInterceptorFn = (req, next) => {
|
||||
return next(req).pipe(catchError((err) => throwError(() => {
|
||||
console.log(err.error);
|
||||
return err.error;
|
||||
})));
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from './api.interceptor';
|
||||
export * from './error.interceptor';
|
||||
//export * from './http.token.interceptor';
|
||||
export * from './token.interceptor';
|
||||
@@ -0,0 +1,13 @@
|
||||
import { inject } from "@angular/core";
|
||||
import { HttpInterceptorFn } from "@angular/common/http";
|
||||
import { JwtService } from "src/app/core/services/jwt.service";
|
||||
|
||||
export const tokenInterceptor: HttpInterceptorFn = (req, next) => {
|
||||
const token = inject(JwtService).getToken();
|
||||
const request = req.clone({
|
||||
setHeaders: {
|
||||
...(token ? { Authorization: `Token ${token}` } : {}),
|
||||
},
|
||||
});
|
||||
return next(request);
|
||||
};
|
||||
Reference in New Issue
Block a user