Fix xsrf error status bug when after beego update

Signed-off-by: Yogi_Wang <yawang@vmware.com>
This commit is contained in:
Yogi_Wang 2020-03-02 10:10:01 +08:00
parent 5f2544941e
commit 2bbb37e6b5
2 changed files with 3 additions and 3 deletions

View File

@ -24,7 +24,7 @@ describe('InterceptHttpService', () => {
return of(new HttpResponse({status: 200}));
} else {
return throwError(new HttpResponse( {
status: 403
status: 422
}));
}
}
@ -48,7 +48,7 @@ describe('InterceptHttpService', () => {
(service: InterceptHttpService) => {
mockCookieService.set("fdsa|ds");
service.intercept(mockRequest, mockHandle).subscribe(res => {
if (res.status === 403) {
if (res.status === 422) {
expect(btoa(mockRequest.headers.get("X-Xsrftoken"))).toEqual(cookie.split("|")[0]);
} else {
expect(res.status).toEqual(200);

View File

@ -14,7 +14,7 @@ export class InterceptHttpService implements HttpInterceptor {
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<any> {
return next.handle(request).pipe(catchError(error => {
if (error.status === 403) {
if (error.status === 422) {
let Xsrftoken = this.cookie.get("_xsrf") ? atob(this.cookie.get("_xsrf").split("|")[0]) : null;
if (Xsrftoken && !request.headers.has('X-Xsrftoken')) {
request = request.clone({ headers: request.headers.set('X-Xsrftoken', Xsrftoken) });