Browse Source

Detect and recover from IndexedDB QuotaExceededError

Fixes #154
Thibaut 10 years ago
parent
commit
9dc99bd8ea

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

@@ -132,6 +132,10 @@
     @hideLoading()
     return
 
+  onQuotaExceeded: ->
+    new app.views.Notif 'QuotaExceeded', autoHide: null
+    Raven.captureMessage 'QuotaExceededError'
+
   onWindowError: (args...) ->
     if @isInjectionError args...
       @onInjectionError()

+ 10 - 3
assets/javascripts/app/db.coffee

@@ -8,7 +8,7 @@ class app.DB
 
   db: (fn) ->
     return fn() unless @useIndexedDB
-    @callbacks.push(fn)
+    @callbacks.push(fn) if fn
     return if @open
 
     try
@@ -39,8 +39,15 @@ class app.DB
 
   onOpenError: (event) =>
     event?.preventDefault()
-    @useIndexedDB = @open = false
-    @runCallbacks()
+    @open = false
+
+    if event?.target?.error?.name is 'QuotaExceededError'
+      @reset()
+      @db()
+      app.onQuotaExceeded()
+    else
+      @useIndexedDB = false
+      @runCallbacks()
     return
 
   runCallbacks: (db) ->

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

@@ -15,6 +15,10 @@ app.templates.notifError = ->
                 <a href="javascript:if(confirm('Are you sure you want to reset DevDocs?'))app.reset()">resetting the app</a>.<br>
                 You can also report this issue on <a href="https://github.com/Thibaut/devdocs/issues/new" target="_blank">GitHub</a>. """
 
+app.templates.notifQuotaExceeded = ->
+  textNotif """ Oops, 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.notifInvalidLocation = ->
   textNotif """ DevDocs must be loaded from #{app.config.production_host} """,
             """ Otherwise things are likely to break. """