History

Better error handling when cookies are disabled

Thibaut Courouble committed 10 years ago

Commit 3eb5a0c1 parent 41faea45 files · +24 −1Browse files

Showing the changes to assets/javascripts (5 of 5 files). Show all

Unified · Split

5 files
  1. assets/javascripts/app/app.coffee +10 −0
  2. assets/javascripts/lib/cookie_store.coffee +3 −1
  3. assets/javascripts/templates/error_tmpl.coffee +3 −0
  4. assets/javascripts/templates/notif_tmpl.coffee +4 −0
  5. assets/javascripts/views/content/offline_page.coffee +4 −0
assets/javascripts/app/app.coffee+10−0
@@ -75,6 +75,7 @@ · 74 unmodified lines
7575 .install()
7676 @previousErrorHandler = onerror
7777 window.onerror = @onWindowError.bind(@)
78+ CookieStore.onBlocked = @onCookieBlocked
7879 return
7980
8081 bootOne: ->
@@ -207,8 +208,17 @@ · 126 unmodified lines
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+3−1
@@ -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 · 6 unmodified lines
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+3−0
@@ -23,6 +23,9 @@ app.templates.bootError = -> · 22 unmodified lines
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+4−0
@@ -19,6 +19,10 @@ app.templates.notifQuotaExceeded = -> · 18 unmodified lines
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+4−0
@@ -11,6 +11,10 @@ class app.views.OfflinePage extends app.View · 10 unmodified lines
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