Forráskód Böngészése

Better error handling when cookies are disabled

Thibaut Courouble 9 éve
szülő
commit
3eb5a0caaa

+ 10 - 0
assets/javascripts/app/app.coffee

@@ -75,6 +75,7 @@
         .install()
       @previousErrorHandler = onerror
       window.onerror = @onWindowError.bind(@)
+      CookieStore.onBlocked = @onCookieBlocked
     return
 
   bootOne: ->
@@ -207,8 +208,17 @@
     @quotaExceeded = true
     new app.views.Notif 'QuotaExceeded', autoHide: null
     Raven.captureMessage 'QuotaExceededError', level: 'warning'
+    return
+
+  onCookieBlocked: (key, value, actual) ->
+    return if @cookieBlocked
+    @cookieBlocked = true
+    new app.views.Notif 'CookieBlocked', autoHide: null
+    Raven.captureMessage "CookieBlocked/#{key}", level: 'warning', extra: {value, actual}
+    return
 
   onWindowError: (args...) ->
+    return if @cookieBlocked
     if @isInjectionError args...
       @onInjectionError()
     else if @isAppError args...

+ 3 - 1
assets/javascripts/lib/cookie_store.coffee

@@ -1,6 +1,8 @@
 class @CookieStore
   INT = /^\d+$/
 
+  @onBlocked: ->
+
   get: (key) ->
     value = Cookies.get(key)
     value = parseInt(value, 10) if value? and INT.test(value)
@@ -13,7 +15,7 @@ class @CookieStore
 
     value = 1 if value == true
     Cookies.set(key, '' + value, path: '/', expires: 1e8)
-    throw new Error("Failed to set cookie '#{key}'") unless @get(key) == value
+    @constructor.onBlocked(key, value, @get(key)) if @get(key) != value
     return
 
   del: (key) ->

+ 3 - 0
assets/javascripts/templates/error_tmpl.coffee

@@ -23,6 +23,9 @@ app.templates.bootError = ->
             If you keep seeing this, you're likely behind a proxy or firewall that blocks cross-domain requests. """
 
 app.templates.offlineError = (reason) ->
+  if reason is 'cookie_blocked'
+    return error """ Cookies must be enabled to use offline mode. """
+
   reason = switch reason
     when 'not_supported'
       """ Unfortunately your browser either doesn't support IndexedDB or does not make it available. """

+ 4 - 0
assets/javascripts/templates/notif_tmpl.coffee

@@ -19,6 +19,10 @@ app.templates.notifQuotaExceeded = ->
   textNotif """ The offline database has exceeded its size limitation. """,
             """ 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. """
 
+app.templates.notifCookieBlocked = ->
+  textNotif """ Please enable cookies. """,
+            """ DevDocs will not work properly if cookies are disabled. """
+
 app.templates.notifInvalidLocation = ->
   textNotif """ DevDocs must be loaded from #{app.config.production_host} """,
             """ Otherwise things are likely to break. """

+ 4 - 0
assets/javascripts/views/content/offline_page.coffee

@@ -11,6 +11,10 @@ class app.views.OfflinePage extends app.View
     return
 
   render: ->
+    if app.cookieBlocked
+      @html @tmpl('offlineError', 'cookie_blocked')
+      return
+
     app.docs.getInstallStatuses (statuses) =>
       return unless @activated
       if statuses is false