Skip to content
This repository has been archived by the owner on Nov 22, 2018. It is now read-only.

Commit

Permalink
go-tour: handle disabled cookies graciously
Browse files Browse the repository at this point in the history
LGTM=adg
R=adg
CC=golang-codereviews
https://codereview.appspot.com/189200043
  • Loading branch information
campoy committed Dec 19, 2014
1 parent 5468207 commit 380396f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions static/js/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ factory('fmt', ['$http',
// Local storage, persistent to page refreshing.
factory('storage', ['$window',
function(win) {
if (win.localStorage) {
try {
// This will raise an exception if cookies are disabled.
win.localStorage = win.localStorage;
return {
get: function(key) {
return win.localStorage.getItem(key);
Expand All @@ -86,13 +88,14 @@ factory('storage', ['$window',
win.localStorage.setItem(key, val);
}
};
} catch (e) {
return {
get: function() {
return null;
},
set: function() {}
};
}
return {
get: function() {
return null;
},
set: function() {}
};
}
]).

Expand Down

0 comments on commit 380396f

Please sign in to comment.