Angular6 catch timeout error

╄→尐↘猪︶ㄣ 提交于 2020-01-04 15:33:34

问题


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));

回答1:


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));


来源:https://stackoverflow.com/questions/51405688/angular6-catch-timeout-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!