History

Better error handling when cookies are disabled

Thibaut Courouble committed 10 years ago

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

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
75 .install()75 .install()
76 @previousErrorHandler = onerror76 @previousErrorHandler = onerror
77 window.onerror = @onWindowError.bind(@)77 window.onerror = @onWindowError.bind(@)
78 CookieStore.onBlocked = @onCookieBlocked
78 return79 return
79 80
80 bootOne: ->81 bootOne: ->
@@ -207,8 +208,17 @@ · 126 unmodified lines
207 @quotaExceeded = true208 @quotaExceeded = true
208 new app.views.Notif 'QuotaExceeded', autoHide: null209 new app.views.Notif 'QuotaExceeded', autoHide: null
209 Raven.captureMessage 'QuotaExceededError', level: 'warning'210 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
210 219
211 onWindowError: (args...) ->220 onWindowError: (args...) ->
221 return if @cookieBlocked
212 if @isInjectionError args...222 if @isInjectionError args...
213 @onInjectionError()223 @onInjectionError()
214 else if @isAppError args...224 else if @isAppError args...
assets/javascripts/lib/cookie_store.coffee+3−1
@@ -1,6 +1,8 @@
1class @CookieStore1class @CookieStore
2 INT = /^\d+$/2 INT = /^\d+$/
3 3
4 @onBlocked: ->
5
4 get: (key) ->6 get: (key) ->
5 value = Cookies.get(key)7 value = Cookies.get(key)
6 value = parseInt(value, 10) if value? and INT.test(value)8 value = parseInt(value, 10) if value? and INT.test(value)
@@ -13,7 +15,7 @@ class @CookieStore · 6 unmodified lines
13 15
14 value = 1 if value == true16 value = 1 if value == true
15 Cookies.set(key, '' + value, path: '/', expires: 1e8)17 Cookies.set(key, '' + value, path: '/', expires: 1e8)
16 throw new Error("Failed to set cookie '#{key}'") unless @get(key) == value18 @constructor.onBlocked(key, value, @get(key)) if @get(key) != value
17 return19 return
18 20
19 del: (key) ->21 del: (key) ->
assets/javascripts/templates/error_tmpl.coffee+3−0
@@ -23,6 +23,9 @@ app.templates.bootError = -> · 22 unmodified lines
23 If you keep seeing this, you're likely behind a proxy or firewall that blocks cross-domain requests. """23 If you keep seeing this, you're likely behind a proxy or firewall that blocks cross-domain requests. """
24 24
25app.templates.offlineError = (reason) ->25app.templates.offlineError = (reason) ->
26 if reason is 'cookie_blocked'
27 return error """ Cookies must be enabled to use offline mode. """
28
26 reason = switch reason29 reason = switch reason
27 when 'not_supported'30 when 'not_supported'
28 """ Unfortunately your browser either doesn't support IndexedDB or does not make it available. """31 """ 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
19 textNotif """ The offline database has exceeded its size limitation. """,19 textNotif """ The offline database has exceeded its size limitation. """,
20 """ 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. """20 """ 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. """
21 21
22app.templates.notifCookieBlocked = ->
23 textNotif """ Please enable cookies. """,
24 """ DevDocs will not work properly if cookies are disabled. """
25
22app.templates.notifInvalidLocation = ->26app.templates.notifInvalidLocation = ->
23 textNotif """ DevDocs must be loaded from #{app.config.production_host} """,27 textNotif """ DevDocs must be loaded from #{app.config.production_host} """,
24 """ Otherwise things are likely to break. """28 """ 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
11 return11 return
12 12
13 render: ->13 render: ->
14 if app.cookieBlocked
15 @html @tmpl('offlineError', 'cookie_blocked')
16 return
17
14 app.docs.getInstallStatuses (statuses) =>18 app.docs.getInstallStatuses (statuses) =>
15 return unless @activated19 return unless @activated
16 if statuses is false20 if statuses is false