Set up our resource retrying mechanism to stop after 20 tries.

This commit is contained in:
Scott Erickson 2014-12-01 16:09:59 -08:00
parent 8ce192bf7c
commit cd5b57a658
2 changed files with 20 additions and 5 deletions

View file

@ -122,6 +122,7 @@ class CocoModel extends Backbone.Model
success = options.success
error = options.error
options.success = (model, res) =>
@retries = 0
@trigger 'save:success', @
success(@, res) if success
@markToRevert() if @_revertAttributes
@ -130,9 +131,16 @@ class CocoModel extends Backbone.Model
options.success = options.error = null # So the callbacks can be garbage-collected.
options.error = (model, res) =>
if res.status is 0
msg = $.i18n.t 'loading_error.connection_failure', defaultValue: 'Connection failed.'
noty text: msg, layout: 'center', type: 'error', killer: true, timeout: 3000
return _.delay((f = => @save(attrs, originalOptions)), 3000)
@retries ?= 0
@retries += 1
if @retries > 20
msg = 'Your computer or our servers appear to be offline. Please try refreshing.'
noty text: msg, layout: 'center', type: 'error', killer: true
return
else
msg = $.i18n.t 'loading_error.connection_failure', defaultValue: 'Connection failed.'
noty text: msg, layout: 'center', type: 'error', killer: true, timeout: 3000
return _.delay((f = => @save(attrs, originalOptions)), 3000)
error(@, res) if error
return unless @notyErrors
errorMessage = "Error saving #{@get('name') ? @type()}"

View file

@ -151,8 +151,15 @@ module.exports = class CocoView extends Backbone.View
onResourceLoadFailed: (e) ->
r = e.resource
if r.jqxhr?.status is 0
@warnConnectionError()
return _.delay (=> r.load()), 3000
r.retries ?= 0
r.retries += 1
if r.retries > 20
msg = 'Your computer or our servers appear to be offline. Please try refreshing.'
noty text: msg, layout: 'center', type: 'error', killer: true
return
else
@warnConnectionError()
return _.delay (=> r.load()), 3000
@$el.find('.loading-container .errors').append(loadingErrorTemplate({
status: r.jqxhr?.status