Set up our resource retrying mechanism to stop after 20 tries.
This commit is contained in:
parent
8ce192bf7c
commit
cd5b57a658
2 changed files with 20 additions and 5 deletions
app
|
@ -122,6 +122,7 @@ class CocoModel extends Backbone.Model
|
||||||
success = options.success
|
success = options.success
|
||||||
error = options.error
|
error = options.error
|
||||||
options.success = (model, res) =>
|
options.success = (model, res) =>
|
||||||
|
@retries = 0
|
||||||
@trigger 'save:success', @
|
@trigger 'save:success', @
|
||||||
success(@, res) if success
|
success(@, res) if success
|
||||||
@markToRevert() if @_revertAttributes
|
@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.success = options.error = null # So the callbacks can be garbage-collected.
|
||||||
options.error = (model, res) =>
|
options.error = (model, res) =>
|
||||||
if res.status is 0
|
if res.status is 0
|
||||||
msg = $.i18n.t 'loading_error.connection_failure', defaultValue: 'Connection failed.'
|
@retries ?= 0
|
||||||
noty text: msg, layout: 'center', type: 'error', killer: true, timeout: 3000
|
@retries += 1
|
||||||
return _.delay((f = => @save(attrs, originalOptions)), 3000)
|
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
|
error(@, res) if error
|
||||||
return unless @notyErrors
|
return unless @notyErrors
|
||||||
errorMessage = "Error saving #{@get('name') ? @type()}"
|
errorMessage = "Error saving #{@get('name') ? @type()}"
|
||||||
|
|
|
@ -151,8 +151,15 @@ module.exports = class CocoView extends Backbone.View
|
||||||
onResourceLoadFailed: (e) ->
|
onResourceLoadFailed: (e) ->
|
||||||
r = e.resource
|
r = e.resource
|
||||||
if r.jqxhr?.status is 0
|
if r.jqxhr?.status is 0
|
||||||
@warnConnectionError()
|
r.retries ?= 0
|
||||||
return _.delay (=> r.load()), 3000
|
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({
|
@$el.find('.loading-container .errors').append(loadingErrorTemplate({
|
||||||
status: r.jqxhr?.status
|
status: r.jqxhr?.status
|
||||||
|
|
Reference in a new issue