相关疑难解决方法(0)

如何在角度http拦截器中引发可观察到的错误

我试图在拦截器中引发可观察到的错误,然后处理该错误。但是我不能。如果成功为假,我也可以收到成功的订阅。

我尝试在中再次返回一个值next.handle(restReq)。但是我失败了,没有订阅任何东西

restApi这样返回

{
  "success": false,
  "data": {
    "name": "Bad Request",
    "message": "123",
    "code": 0,
    "status": 400,
    "type": "yii\\web\\BadRequestHttpException"
  }
}
Run Code Online (Sandbox Code Playgroud)

验证服务

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/internal/Observable';

@Injectable({
  providedIn: 'root'
})
export class AuthService {
  private sessionUrl = '/wechat/session';

  constructor(
    private http: HttpClient
  ) { }

  getSession(): Observable<any> {
    return this.http.post<any>(this.sessionUrl, {});
  }
}
Run Code Online (Sandbox Code Playgroud)

auth.component.ts

import { Component, OnInit } from '@angular/core';
import { AuthService …
Run Code Online (Sandbox Code Playgroud)

angular angular5 angular6

5
推荐指数
2
解决办法
5289
查看次数

标签 统计

angular ×1

angular5 ×1

angular6 ×1