Let $.cache report connection errors.

This commit is contained in:
ccd0 2019-03-09 02:13:19 -08:00
parent a7af355820
commit 78a79f1942
6 changed files with 12 additions and 13 deletions

View File

@ -66,6 +66,7 @@ Build.Test =
testOne: (post) -> testOne: (post) ->
Build.Test.postsRemaining++ Build.Test.postsRemaining++
$.cache "#{location.protocol}//a.4cdn.org/#{post.board.ID}/thread/#{post.thread.ID}.json", -> $.cache "#{location.protocol}//a.4cdn.org/#{post.board.ID}/thread/#{post.thread.ID}.json", ->
return unless @response
{posts} = @response {posts} = @response
Build.spoilerRange[post.board.ID] = posts[0].custom_spoiler Build.spoilerRange[post.board.ID] = posts[0].custom_spoiler
for postData in posts for postData in posts

View File

@ -38,7 +38,7 @@ ExpandComment =
parse: (req, a, post) -> parse: (req, a, post) ->
{status} = req {status} = req
unless status in [200, 304] unless status in [200, 304]
a.textContent = "Error #{req.statusText} (#{status})" a.textContent = if status then "Error #{req.statusText} (#{status})" else 'Connection Error'
return return
posts = req.response.posts posts = req.response.posts

View File

@ -89,7 +89,7 @@ ExpandThread =
parse: (req, thread, a) -> parse: (req, thread, a) ->
if req.status not in [200, 304] 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 return
Build.spoilerRange[thread.board] = req.response.posts[0].custom_spoiler Build.spoilerRange[thread.board] = req.response.posts[0].custom_spoiler

View File

@ -61,12 +61,14 @@ class Fetcher
{status} = req {status} = req
unless status is 200 unless status is 200
# The thread can die by the time we check a quote. # The thread can die by the time we check a quote.
return if @archivedPost() return if status and @archivedPost()
$.addClass @root, 'warning' $.addClass @root, 'warning'
@root.textContent = @root.textContent =
if status is 404 if status is 404
"Thread No.#{@threadID} 404'd." "Thread No.#{@threadID} 404'd."
else if !status
'Connection Error'
else else
"Error #{req.statusText} (#{req.status})." "Error #{req.statusText} (#{req.status})."
return return

View File

@ -92,12 +92,11 @@ do ->
$.queueTask -> cb.call req, {isCached: true} $.queueTask -> cb.call req, {isCached: true}
return req return req
options.onloadend = -> options.onloadend = ->
if @status unless @status
for cb in @callbacks
do (cb) => $.queueTask => cb.call @, {isCached: false}
delete @callbacks
else
delete reqs[url] delete reqs[url]
for cb in @callbacks
do (cb) => $.queueTask => cb.call @, {isCached: false}
delete @callbacks
req = $.ajax url, options req = $.ajax url, options
req.callbacks = [cb] req.callbacks = [cb]
reqs[url] = req reqs[url] = req

View File

@ -70,7 +70,7 @@ CrossOrigin =
# Attempts to fetch `url` in JSON format using cross-origin privileges, if available. # 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 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. # If `bypassCache` is true, ignores previously cached results.
json: do -> json: do ->
callbacks = {} callbacks = {}
@ -90,10 +90,7 @@ CrossOrigin =
unless GM?.xmlHttpRequest? or GM_xmlhttpRequest? unless GM?.xmlHttpRequest? or GM_xmlhttpRequest?
if bypassCache if bypassCache
$.cleanCache (url2) -> url2 is url $.cleanCache (url2) -> url2 is url
if (req = $.cache url, cb) req = $.cache url, cb
$.on req, 'abort error', -> cb.call({})
else
cb.call {}
return return
<% } %> <% } %>