Disable SuperModel retrying

Seems to be causing issues when requests retry with different parameters,
for example:

https://github.com/codecombat/codecombat/blob/master/app/views/NewHomeView.coffee#L42-L45

This retries without the original GET parameters and returns a 403 as a result.
This commit is contained in:
Scott Erickson 2016-08-11 09:44:36 -07:00
parent 37d0b23103
commit d679700966

View file

@ -298,33 +298,37 @@ class ModelResource extends Resource
@loadsAttempted = 0
load: ->
# TODO: Track progress on requests and don't retry if progress was made recently.
# Probably use _.debounce and attach event listeners to xhr objects.
# This logic is for handling failed responses for level loading.
timeToWait = 5000
tryLoad = =>
return if this.isLoaded
if @loadsAttempted > 4
@markFailed()
return @
@markLoading()
@model.loading = false # So fetchModel can run again
if @loadsAttempted > 0
console.log "Didn't load model in #{timeToWait}ms (attempt ##{@loadsAttempted}), trying again: ", _.result(@model, 'url')
@fetchModel()
@listenTo @model, 'error', (levelComponent, request) ->
if request.status not in [408, 504, 522, 524]
clearTimeout(@timeoutID)
clearTimeout(@timeoutID) if @timeoutID
@timeoutID = setTimeout(tryLoad, timeToWait)
if application.testing
application.timeoutsToClear?.push(@timeoutID)
@loadsAttempted += 1
timeToWait *= 1.5
tryLoad()
@markLoading()
@fetchModel()
@
# # TODO: Track progress on requests and don't retry if progress was made recently.
# # Probably use _.debounce and attach event listeners to xhr objects.
#
# # This logic is for handling failed responses for level loading.
# timeToWait = 5000
# tryLoad = =>
# return if this.isLoaded
# if @loadsAttempted > 4
# @markFailed()
# return @
# @markLoading()
# @model.loading = false # So fetchModel can run again
# if @loadsAttempted > 0
# console.log "Didn't load model in #{timeToWait}ms (attempt ##{@loadsAttempted}), trying again: ", _.result(@model, 'url')
# @fetchModel()
# @listenTo @model, 'error', (levelComponent, request) ->
# if request.status not in [408, 504, 522, 524]
# clearTimeout(@timeoutID)
# clearTimeout(@timeoutID) if @timeoutID
# @timeoutID = setTimeout(tryLoad, timeToWait)
# if application.testing
# application.timeoutsToClear?.push(@timeoutID)
# @loadsAttempted += 1
# timeToWait *= 1.5
# tryLoad()
# @
fetchModel: ->
@jqxhr = @model.fetch(@fetchOptions) unless @model.loading
@listen()