gpt4 book ai didi

Angular 2 http 没有捕获连接被拒绝的错误

转载 作者:太空狗 更新时间:2023-10-29 17:39:33 25 4
gpt4 key购买 nike

我想捕获所有 http 错误以通知用户发生了问题。

因此,我创建了一个方法来执行 http get with a catch。

get(path: string): Promise<any> {
let headers = new Headers();
return this.http.get(path, { headers: headers })
.toPromise()
.then(response => { ... })
.catch((response: Response) => { this.errorHandler(response); });
}

当路径参数为“/fault-url”时,将按预期处理捕获。

但是当路径是 ' http://localhost:5000/fault-url ' 错误未被 catch 方法捕获。我已经在所有不同的地方添加了日志记录,但它接缝了 get 方法只是中止。控制台日志显示以下错误

OPTIONS http://localhost:5000/fault-url net::ERR_CONNECTION_REFUSED

EXCEPTION: Response with status: 0 for URL: null

Uncaught Response {_body: ProgressEvent, status: 0, ok: false, statusText: "", headers: Headers…}

http 真的中止了还是我做错了什么?

最佳答案

升级到 Angular 2.3.0 后问题解决。

关于Angular 2 http 没有捕获连接被拒绝的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41055271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com