Skip to content

Commit

Permalink
handled js cookie errors when cookies are not available.
Browse files Browse the repository at this point in the history
  • Loading branch information
NizamLZ committed Apr 17, 2018
1 parent be8ca86 commit 3323377
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/assets/embed/ana-web-chat-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@
};
},
setCookie: (name, value, days = 7, path = '/') => {
const expires = new Date(Date.now() + days * 864e5).toUTCString()
document.cookie = name + '=' + encodeURIComponent(value) + '; expires=' + expires + '; path=' + path
try {
const expires = new Date(Date.now() + days * 864e5).toUTCString()
document.cookie = name + '=' + encodeURIComponent(value) + '; expires=' + expires + '; path=' + path
} catch (e) {
}
},
getCookie: (name) => {
return document.cookie.split('; ').reduce((r, v) => {
const parts = v.split('=')
return parts[0] === name ? decodeURIComponent(parts[1]) : r
}, '')
try {
return document.cookie.split('; ').reduce((r, v) => {
const parts = v.split('=')
return parts[0] === name ? decodeURIComponent(parts[1]) : r
}, '')
} catch (e) {
return '';
}
},
deleteCookie: (name, path) => {
setCookie(name, '', -1, path)
Expand Down

0 comments on commit 3323377

Please sign in to comment.