我想捕获所有http错误,以通知用户发生的问题.
所以,我创建了一个使用catch执行http get的方法.
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); });
}
Run Code Online (Sandbox Code Playgroud)
当path参数为'/ fault-url'时,catch按预期处理.
但是当路径为' http:// localhost:5000/fault-url '时,catch方法不会捕获错误.我已经将日志记录添加到所有不同的地方,但它接收get方法只是中止.控制台日志显示以下错误
选项http:// localhost:5000/fault-url net :: ERR_CONNECTION_REFUSED
EXCEPTION:响应状态:URL为0:null
未捕获的响应{_body:ProgressEvent,status:0,ok:false,statusText:"",headers:Headers ...}
http真的中止还是我做错了什么?
我在 Docker 容器中运行 Wildfly。在 Wildfly 中,messaging-activemq 子系统处于活动状态。子系统和扩展默认值取自standalone-full.xml 文件。
启动wildfly后,显示以下输出
[org.apache.activemq.artemis.jms.server] (ServerService Thread Pool -- 64)
AMQ121005: Invalid "host" value "0.0.0.0" detected for "http-connector" connector.
Switching to "eeb79399d447".
If this new address is incorrect please manually configure the connector to use the proper one.
Run Code Online (Sandbox Code Playgroud)
eeb79399d447 是 docker 容器 ID。我的 java 客户端也无法连接到 jms。连接时出现以下错误。
AMQ214016: Failed to create netty connection: java.net.UnknownHostException: eeb79399d447
Run Code Online (Sandbox Code Playgroud)
当我在本地工作站(docker 外部)上启动 wildfly 时,问题不会发生,我可以连接到 jms 并发送消息。