I'm working on a large Angular application and need to present the user with an error message if they have cookies disabled.
The trouble is thus: Angular crashes when it attempts to load a module that attempts to access local storage when cookies are disabled with the follow error message:
Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.
The error is thrown by Angular here:
function getService(serviceName, caller) {
if (cache.hasOwnProperty(serviceName)) {
if (cache[serviceName] === INSTANTIATING) {
throw $injectorMinErr('cdep', 'Circular dependency found: {0}',
serviceName + ' <- ' + path.join(' <- '));
}
return cache[serviceName];
} else {
try {
path.unshift(serviceName);
cache[serviceName] = INSTANTIATING;
return cache[serviceName] = factory(serviceName, caller);
} catch (err) {
if (cache[serviceName] === INSTANTIATING) {
delete cache[serviceName];
}
throw err; // THIS IS WHATS BEING THROWN
} finally {
path.shift();
}
}
}
MANY components of this application access localStorage in one way or another, and it seems inelegant to simply hard-redirect them to another page simply to display this error.
Has anyone else run into this issue?