Skip to content

Commit 9dc99bd

Browse files
committed
Detect and recover from IndexedDB QuotaExceededError
Fixes freeCodeCamp#154
1 parent 1b6ded9 commit 9dc99bd

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

assets/javascripts/app/app.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@
132132
@hideLoading()
133133
return
134134

135+
onQuotaExceeded: ->
136+
new app.views.Notif 'QuotaExceeded', autoHide: null
137+
Raven.captureMessage 'QuotaExceededError'
138+
135139
onWindowError: (args...) ->
136140
if @isInjectionError args...
137141
@onInjectionError()

assets/javascripts/app/db.coffee

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class app.DB
88

99
db: (fn) ->
1010
return fn() unless @useIndexedDB
11-
@callbacks.push(fn)
11+
@callbacks.push(fn) if fn
1212
return if @open
1313

1414
try
@@ -39,8 +39,15 @@ class app.DB
3939

4040
onOpenError: (event) =>
4141
event?.preventDefault()
42-
@useIndexedDB = @open = false
43-
@runCallbacks()
42+
@open = false
43+
44+
if event?.target?.error?.name is 'QuotaExceededError'
45+
@reset()
46+
@db()
47+
app.onQuotaExceeded()
48+
else
49+
@useIndexedDB = false
50+
@runCallbacks()
4451
return
4552

4653
runCallbacks: (db) ->

assets/javascripts/templates/notif_tmpl.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ app.templates.notifError = ->
1515
<a href="javascript:if(confirm('Are you sure you want to reset DevDocs?'))app.reset()">resetting the app</a>.<br>
1616
You can also report this issue on <a href="https://github.com/Thibaut/devdocs/issues/new" target="_blank">GitHub</a>. """
1717

18+
app.templates.notifQuotaExceeded = ->
19+
textNotif """ Oops, 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. """
21+
1822
app.templates.notifInvalidLocation = ->
1923
textNotif """ DevDocs must be loaded from #{app.config.production_host} """,
2024
""" Otherwise things are likely to break. """

0 commit comments

Comments
 (0)