Merge pull request #13175 from AllForNothing/504

Handle 504 error from backend
This commit is contained in:
Will Sun 2020-09-28 18:52:53 +08:00 committed by GitHub
commit d5322c3d45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpResponse } from '@angular/common/http'; import { HttpInterceptor, HttpRequest, HttpHandler, HttpResponse, HttpErrorResponse } from '@angular/common/http';
import { Observable, throwError } from 'rxjs'; import { Observable, throwError } from 'rxjs';
import { catchError, tap } from 'rxjs/operators'; import { catchError, tap } from 'rxjs/operators';
@ -44,6 +44,14 @@ export class InterceptHttpService implements HttpInterceptor {
})) }))
.pipe( .pipe(
catchError(error => { catchError(error => {
// handle 504 error in document format from backend
if (error && error.status === 504) {
// throw 504 error in json format
return throwError(new HttpErrorResponse({
error: '504 gateway timeout',
status: 504
}));
}
if (error.status === 403) { if (error.status === 403) {
const csrfToken = localStorage.getItem("__csrf"); const csrfToken = localStorage.getItem("__csrf");
if (csrfToken) { if (csrfToken) {