You may want to go about solving this issue by making use of the $httpProvider.interceptors
.
In your case you could catch the 500
error coming from /api/users
(though probably better to return a 401
or 403
) and have an interceptor kick in and take the user to /login
.
Here's the official doc:
http://docs.angularjs.org/api/ng/service/$http#interceptors
Here's a more specific example:
http://blog.thesparktree.com/post/75952317665/angularjs-interceptors-globally-handle-401-and-other
And here's a similar answer.