From 4baf45c36ad82b5309a8045afd5b452cbbe481db Mon Sep 17 00:00:00 2001 From: uu59 Date: Tue, 3 Jun 2014 15:46:14 +0900 Subject: [PATCH] Stop polling if receive 401 response --- app/assets/javascripts/alert.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/alert.js b/app/assets/javascripts/alert.js index 9523597..6b4eaa9 100644 --- a/app/assets/javascripts/alert.js +++ b/app/assets/javascripts/alert.js @@ -15,10 +15,14 @@ var fetch = function(){ self.fetchAlertsData().then(function(alerts){ self.alerts = alerts; + })["catch"](function(xhr){ + if(xhr.status === 401) { + clearInterval(timer); + } }); }; fetch(); - setInterval(fetch, POLLING_INTERVAL); + var timer = setInterval(fetch, POLLING_INTERVAL); }, computed: {