简体   繁体   中英

How to watch every API reponse in angular?

In my case, most of the time API returns some response like data or error, but sometimes request are sent to the server, but there is no response on longtime. I need to watch every API call after the request is sent, if no response from the server for up to 3 mins, then we will refresh the app or log out.

How to do this In angular?

Please help me out.

HttpInterceptor , you can create a timer on your interceptor to do so. though I am not sure if you really want to logout the user when the server does not respond, the correct way to handle it is usually to give a popup error to the user.

Also, server request should not take that long, should inspect the back-end too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM