Skip to content

Commit 3eb5a0c

Browse files
committed
Better error handling when cookies are disabled
1 parent 41faea4 commit 3eb5a0c

5 files changed

Lines changed: 24 additions & 1 deletion

File tree

assets/javascripts/app/app.coffee

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
.install()
7676
@previousErrorHandler = onerror
7777
window.onerror = @onWindowError.bind(@)
78+
CookieStore.onBlocked = @onCookieBlocked
7879
return
7980

8081
bootOne: ->
@@ -207,8 +208,17 @@
207208
@quotaExceeded = true
208209
new app.views.Notif 'QuotaExceeded', autoHide: null
209210
Raven.captureMessage 'QuotaExceededError', level: 'warning'
211+
return
212+
213+
onCookieBlocked: (key, value, actual) ->
214+
return if @cookieBlocked
215+
@cookieBlocked = true
216+
new app.views.Notif 'CookieBlocked', autoHide: null
217+
Raven.captureMessage "CookieBlocked/#{key}", level: 'warning', extra: {value, actual}
218+
return
210219

211220
onWindowError: (args...) ->
221+
return if @cookieBlocked
212222
if @isInjectionError args...
213223
@onInjectionError()
214224
else if @isAppError args...

assets/javascripts/lib/cookie_store.coffee

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
class @CookieStore
22
INT = /^\d+$/
33

4+
@onBlocked: ->
5+
46
get: (key) ->
57
value = Cookies.get(key)
68
value = parseInt(value, 10) if value? and INT.test(value)
@@ -13,7 +15,7 @@ class @CookieStore
1315

1416
value = 1 if value == true
1517
Cookies.set(key, '' + value, path: '/', expires: 1e8)
16-
throw new Error("Failed to set cookie '#{key}'") unless @get(key) == value
18+
@constructor.onBlocked(key, value, @get(key)) if @get(key) != value
1719
return
1820

1921
del: (key) ->

assets/javascripts/templates/error_tmpl.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ app.templates.bootError = ->
2323
If you keep seeing this, you're likely behind a proxy or firewall that blocks cross-domain requests. """
2424

2525
app.templates.offlineError = (reason) ->
26+
if reason is 'cookie_blocked'
27+
return error """ Cookies must be enabled to use offline mode. """
28+
2629
reason = switch reason
2730
when 'not_supported'
2831
""" Unfortunately your browser either doesn't support IndexedDB or does not make it available. """

assets/javascripts/templates/notif_tmpl.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ app.templates.notifQuotaExceeded = ->
1919
textNotif """ The offline database has exceeded its size limitation. """,
2020
""" Unfortunately this quota can't be detected programmatically, and the database can't be opened while over the quota, so it had to be reset. """
2121

22+
app.templates.notifCookieBlocked = ->
23+
textNotif """ Please enable cookies. """,
24+
""" DevDocs will not work properly if cookies are disabled. """
25+
2226
app.templates.notifInvalidLocation = ->
2327
textNotif """ DevDocs must be loaded from #{app.config.production_host} """,
2428
""" Otherwise things are likely to break. """

assets/javascripts/views/content/offline_page.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ class app.views.OfflinePage extends app.View
1111
return
1212

1313
render: ->
14+
if app.cookieBlocked
15+
@html @tmpl('offlineError', 'cookie_blocked')
16+
return
17+
1418
app.docs.getInstallStatuses (statuses) =>
1519
return unless @activated
1620
if statuses is false

0 commit comments

Comments
 (0)