Let $.cache report connection errors.
This commit is contained in:
parent
a7af355820
commit
78a79f1942
@ -66,6 +66,7 @@ Build.Test =
|
||||
testOne: (post) ->
|
||||
Build.Test.postsRemaining++
|
||||
$.cache "#{location.protocol}//a.4cdn.org/#{post.board.ID}/thread/#{post.thread.ID}.json", ->
|
||||
return unless @response
|
||||
{posts} = @response
|
||||
Build.spoilerRange[post.board.ID] = posts[0].custom_spoiler
|
||||
for postData in posts
|
||||
|
||||
@ -38,7 +38,7 @@ ExpandComment =
|
||||
parse: (req, a, post) ->
|
||||
{status} = req
|
||||
unless status in [200, 304]
|
||||
a.textContent = "Error #{req.statusText} (#{status})"
|
||||
a.textContent = if status then "Error #{req.statusText} (#{status})" else 'Connection Error'
|
||||
return
|
||||
|
||||
posts = req.response.posts
|
||||
|
||||
@ -89,7 +89,7 @@ ExpandThread =
|
||||
|
||||
parse: (req, thread, a) ->
|
||||
if req.status not in [200, 304]
|
||||
a.textContent = "Error #{req.statusText} (#{req.status})"
|
||||
a.textContent = if req.status then "Error #{req.statusText} (#{req.status})" else 'Connection Error'
|
||||
return
|
||||
|
||||
Build.spoilerRange[thread.board] = req.response.posts[0].custom_spoiler
|
||||
|
||||
@ -61,12 +61,14 @@ class Fetcher
|
||||
{status} = req
|
||||
unless status is 200
|
||||
# The thread can die by the time we check a quote.
|
||||
return if @archivedPost()
|
||||
return if status and @archivedPost()
|
||||
|
||||
$.addClass @root, 'warning'
|
||||
@root.textContent =
|
||||
if status is 404
|
||||
"Thread No.#{@threadID} 404'd."
|
||||
else if !status
|
||||
'Connection Error'
|
||||
else
|
||||
"Error #{req.statusText} (#{req.status})."
|
||||
return
|
||||
|
||||
@ -92,12 +92,11 @@ do ->
|
||||
$.queueTask -> cb.call req, {isCached: true}
|
||||
return req
|
||||
options.onloadend = ->
|
||||
if @status
|
||||
for cb in @callbacks
|
||||
do (cb) => $.queueTask => cb.call @, {isCached: false}
|
||||
delete @callbacks
|
||||
else
|
||||
unless @status
|
||||
delete reqs[url]
|
||||
for cb in @callbacks
|
||||
do (cb) => $.queueTask => cb.call @, {isCached: false}
|
||||
delete @callbacks
|
||||
req = $.ajax url, options
|
||||
req.callbacks = [cb]
|
||||
reqs[url] = req
|
||||
|
||||
@ -70,7 +70,7 @@ CrossOrigin =
|
||||
|
||||
# Attempts to fetch `url` in JSON format using cross-origin privileges, if available.
|
||||
# On success, calls `cb` with a `this` containing properties `status`, `statusText`, `response` and caches result.
|
||||
# On error/abort, calls `cb` with a `this` of `{}`.
|
||||
# On error/abort/timeout, calls `cb` with a `this` of `{}` or in some cases an XMLHttpRequest reflecting the error.
|
||||
# If `bypassCache` is true, ignores previously cached results.
|
||||
json: do ->
|
||||
callbacks = {}
|
||||
@ -90,10 +90,7 @@ CrossOrigin =
|
||||
unless GM?.xmlHttpRequest? or GM_xmlhttpRequest?
|
||||
if bypassCache
|
||||
$.cleanCache (url2) -> url2 is url
|
||||
if (req = $.cache url, cb)
|
||||
$.on req, 'abort error', -> cb.call({})
|
||||
else
|
||||
cb.call {}
|
||||
req = $.cache url, cb
|
||||
return
|
||||
<% } %>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user