From bdc15b1cdf52e8eb225ad0e18470650078d868c0 Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Mon, 5 Sep 2016 15:32:51 -0400 Subject: [PATCH] Don't swallow errors when setting cookies --- assets/javascripts/lib/cookie_store.coffee | 27 +++++++++------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/assets/javascripts/lib/cookie_store.coffee b/assets/javascripts/lib/cookie_store.coffee index 6eb36912..1e033d5d 100644 --- a/assets/javascripts/lib/cookie_store.coffee +++ b/assets/javascripts/lib/cookie_store.coffee @@ -2,28 +2,23 @@ class @CookieStore INT = /^\d+$/ get: (key) -> - try - value = Cookies.get(key) - value = parseInt(value, 10) if value? and INT.test(value) - value - catch + value = Cookies.get(key) + value = parseInt(value, 10) if value? and INT.test(value) + value set: (key, value) -> if value == false - return @del(key) - else if value == true - value = 1 + @del(key) + return - try - Cookies.set(key, '' + value, path: '/', expires: 1e8) - true - catch + value = 1 if value == true + Cookies.set(key, '' + value, path: '/', expires: 1e8) + throw new Error("Failed to set cookie '#{key}'") unless @get(key) == value + return del: (key) -> - try - Cookies.expire(key) - true - catch + Cookies.expire(key) + return reset: -> try