Angular6 捕获超时错误 [英] Angular6 catch timeout error
本文介绍了Angular6 捕获超时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用此代码,我可以捕获所有异常,但服务器不可用时除外.您知道应该如何处理吗?
with this code I can catch all the exceptions, except the when the server is anavailable. Do you have any idea about how should be handle ?
return this.http.post<User>(this._appSetting.ebit.base_url "rested/login/login", JSON.stringify(params), httpOptions)
.pipe(catchError(this.handleError));
推荐答案
您可以使用 timeout()
运算符来捕获超时.它以毫秒为单位测量,所以 10000
将是 10 秒.
You can use the timeout()
operator to catch a timeout. It's measured in milliseconds so 10000
would be 10 seconds.
return this.http.post<User>(this._appSetting.ebit.base_url "rested/login/login", JSON.stringify(params), httpOptions)
.pipe(timeout(10000), catchError(this.handleError));
这篇关于Angular6 捕获超时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文