small medium large xlarge

Gabe_pragsmall
26 Oct 2017, 17:46
Gabriel Sanchez (3 posts)

I followed along with the book and created a different app using the steps provided in the book. Things are working great. That being said, I have stumbled upon a problem that I had taken for granted. How do I deal with Session Timeouts? Normally in rails, devise would auto-magically redirect me to the login screen. I found that with the asynchronous http get calls, I get a nice pretty error.

Can you recommend something to handle 401 errors?

Dmfcb_pragsmall
26 Oct 2017, 17:49
David Copeland (479 posts)

Yeah, this is tricky. The way I’ve handled this is to have my HTTP Ajax handlers check for a 401 and if they find it, set window.location to the login screen, or to ask the browser to do a refresh (which would then do the devise-controlled redirect).

Gabe_pragsmall
26 Oct 2017, 23:47
Gabriel Sanchez (3 posts)

I like the browser refresh idea. Works perfectly.

Thanks!

Dmfcb_pragsmall
27 Oct 2017, 01:26
David Copeland (479 posts)

One other “gotcha” that I experienced is that timeouts to the server—which you’d expect to have a 504 or even a 503, often come back as a status of 0. I ended up having to implement a bunch of retry logic on AJAX requests for an app running on a slow network, and was surprised at the invalid http status of 0 :(

Gabe_pragsmall
28 Oct 2017, 01:24
Gabriel Sanchez (3 posts)

I’ll keep an eye out for those type of errors. Prior to posting the original question, I did some searches and found that people were implementing Angular specific global handling of these type of errors. The searches revealed something called interceptors as well as extending the Http class itself to handle the errors.

I might revisit these options when I have more time to really delve into the complexities of Angular.

Thanks again.

You must be logged in to comment