我的服务器总是以200状态响应,但在正文中响应errorCode。我想拦截该响应并将状态重写为403或500.如何使用新的http拦截器执行此操作?这是迄今为止的代码
@Injectable()
export class ApiInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler):
Observable<HttpEvent<any>> {
return next.handle(req)
.map((event: HttpEvent<any>) => {
if (event instanceof HttpResponse && (event.body.errorCode)) {
return event.clone({status: 500})
}
});
}
}