相关疑难解决方法(0)

throwError(error) 现已弃用,但没有新的 Error(HttpErrorResponse)

显然throwError(error)现在已被弃用。VS Code 的 IntelliSense 建议throwError(() => new Error('error')new Error(...)仅接受字符串。在不破坏我的情况下更换它的正确方法是什么HttpErrorHandlerService

\n

http-error.interceptor.ts

\n
import { Injectable } from '@angular/core';\nimport {\n  HttpEvent,\n  HttpInterceptor,\n  HttpHandler,\n  HttpRequest,\n  HttpErrorResponse,\n  HttpResponse,\n  HttpHeaders\n} from '@angular/common/http';\nimport { Observable, EMPTY, finalize, catchError, timeout, map, throwError } from 'rxjs';\n\nimport { HttpErrorHandlerService } from '@core/services';\n\n@Injectable()\nexport class HttpErrorInterceptor implements HttpInterceptor {\n  private readonly APP_XHR_TIMEOUT = 6000;\n\n  constructor(private errorHandlerService: HttpErrorHandlerService) {}\n\n  intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\n    return next.handle(this.performRequest(request)).pipe(\n      timeout(this.APP_XHR_TIMEOUT),\n      map((event: HttpEvent<any>) => this.handleSuccessfulResponse(event)),\n      catchError((error: …
Run Code Online (Sandbox Code Playgroud)

rxjs typescript angular angular12

83
推荐指数
2
解决办法
6万
查看次数

标签 统计

angular ×1

angular12 ×1

rxjs ×1

typescript ×1