how to throw observable error in angular http interceptor

前端 未结 3 1195
慢半拍i
慢半拍i 2020-12-19 04:04

I tried to throw an observable error in the interceptor and then handles this error. but I can\'t. When success is false, I can also receive successful subscribe.

I

3条回答
  •  误落风尘
    2020-12-19 04:44

    Try doing this in your interceptor

    return next.handle(request).map((event: HttpEvent) => {
      if (event instanceof HttpResponse && !event.body.success) {
        throw new Error(event.body.message);
      }
      return event;
      );
    

提交回复
热议问题