如何解决映射Angular HttpClient错误及其类型
我想用其类型映射HttpClient的错误,并且我有以下代码:
export class ErrorMessageInterceptor implements HttpInterceptor {
constructor(private notifyService: NotifyService) {}
public intercept(req: HttpRequest<any>,next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(req).pipe(
catchError(error => {
console.error(error);
return throwError({
ok: error.ok,status: error.status,statusText: error.statusText,code: error.error.error.code,message: error.error.error.message,headers: error.headers,url: error.url,} as OdataError);
}),tap(() => {},async error => {
await this.notifyService.error(error.message);
}),);
}
}
但是不幸的是,error
运算符中tap
的默认类型仍然是any
,并且我不想将错误类型映射到将要使用的任何位置。所以我在这里有两个问题:
- 为什么在上面的代码中看不到映射的类型错误?
- 是否有办法全局设置自定义错误类型,或者至少为注入的
HttpClient
实例设置自定义错误类型?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。