improve error handling

This commit is contained in:
ccd0 2014-07-26 19:00:57 -07:00
parent 2128660c0b
commit 3aa96b32f0
5 changed files with 38 additions and 42 deletions

View File

@ -86,7 +86,7 @@ Header =
# Wait for #boardNavMobile instead of #boardNavDesktop, # Wait for #boardNavMobile instead of #boardNavDesktop,
# it might be incomplete otherwise. # it might be incomplete otherwise.
$.asap (-> $.id('boardNavMobile') or d.readyState isnt 'loading'), Header.setBoardList $.asap (-> $.id('boardNavMobile') or d.readyState isnt 'loading'), Header.setBoardList
$.prepend d.body, @bar $.prepend d.body, [@bar, @noticesRoot]
$.add d.body, Header.hover $.add d.body, Header.hover
@setBarPosition Conf['Bottom Header'] @setBarPosition Conf['Bottom Header']
@ @
@ -142,7 +142,7 @@ Header =
$.rm $ '#navtopright', fullBoardList $.rm $ '#navtopright', fullBoardList
$.add boardList, fullBoardList $.add boardList, fullBoardList
$.add Header.bar, [Header.boardList, Header.shortcuts, Header.noticesRoot, Header.toggle] $.add Header.bar, [Header.boardList, Header.shortcuts, Header.toggle]
Header.setCustomNav Conf['Custom Board Navigation'] Header.setCustomNav Conf['Custom Board Navigation']
Header.generateBoardList Conf['boardnav'].replace /(\r\n|\n|\r)/g, ' ' Header.generateBoardList Conf['boardnav'].replace /(\r\n|\n|\r)/g, ' '
@ -308,18 +308,15 @@ Header =
'bottom-header' 'bottom-header'
'top-header' 'top-header'
'bottom' 'bottom'
'after'
] else [ ] else [
'top-header' 'top-header'
'bottom-header' 'bottom-header'
'top' 'top'
'add'
] ]
$.addClass doc, args[0] $.addClass doc, args[0]
$.rmClass doc, args[1] $.rmClass doc, args[1]
Header.bar.parentNode.className = args[2] Header.bar.parentNode.className = args[2]
$[args[3]] Header.bar, Header.noticesRoot
toggleBarPosition: -> toggleBarPosition: ->
$.cb.checked.call @ $.cb.checked.call @

View File

@ -181,7 +181,9 @@ Gallery =
Gallery.build @ Gallery.build @
error: (file, thumb) -> error: (file, thumb) ->
ImageCommon.error file, g.posts[file.dataset.post], -> if file.error?.code is MediaError.MEDIA_ERR_DECODE
return new Notice 'error', 'Corrupt or unplayable video', 30
ImageCommon.error g.posts[file.dataset.post], null, ->
thumb.href = URL thumb.href = URL
file.src = URL if Gallery.nodes.current is file file.src = URL if Gallery.nodes.current is file

View File

@ -1,34 +1,25 @@
ImageCommon = ImageCommon =
error: (file, post, redirect, reload) -> decodeError: (file, post) ->
if file.error and file.error.code isnt file.error.MEDIA_ERR_NETWORK # video return false unless file.error?.code is MediaError.MEDIA_ERR_DECODE
error = switch file.error.code unless message = $ '.warning', post.file.thumb.parentNode
when 1 then 'MEDIA_ERR_ABORTED' message = $.el 'div', className: 'warning'
when 3 then 'MEDIA_ERR_DECODE' $.after post.file.thumb, message
when 4 then 'MEDIA_ERR_SRC_NOT_SUPPORTED' message.textContent = 'Error: Corrupt or unplayable video'
when 5 then 'MEDIA_ERR_ENCRYPTED' return true
unless message = $ '.warning', post.file.thumb.parentNode
message = $.el 'div', className: 'warning'
$.after post.file.thumb, message
message.textContent = "Playback error: #{error}"
return
src = file.src.split '/' error: (post, delay, cb) ->
if src[2] is 'i.4cdn.org' timeoutID = setTimeout ImageCommon.retry, delay, post, cb if delay?
URL = Redirect.to 'file', return if post.isDead or post.file.isDead
boardID: src[3] kill = (fileOnly) ->
filename: src[src.length - 1].replace /\?.+$/, '' clearTimeout timeoutID
if URL and (/^https:\/\//.test(URL) or location.protocol is 'http:') post.kill fileOnly
return redirect URL ImageCommon.retry post, cb
if g.DEAD or post.isDead or post.file.isDead
return
timeoutID = reload?()
<% if (type === 'crx') { %> <% if (type === 'crx') { %>
$.ajax post.file.URL, $.ajax post.file.URL,
onloadend: -> onloadend: ->
return if @status isnt 404 return if @status isnt 404
clearTimeout timeoutID kill true
post.kill true
, ,
type: 'head' type: 'head'
<% } else { %> <% } else { %>
@ -38,9 +29,16 @@ ImageCommon =
for postObj in @response.posts for postObj in @response.posts
break if postObj.no is post.ID break if postObj.no is post.ID
if postObj.no isnt post.ID if postObj.no isnt post.ID
clearTimeout timeoutID kill()
post.kill()
else if postObj.filedeleted else if postObj.filedeleted
clearTimeout timeoutID kill true
post.kill true
<% } %> <% } %>
retry: (post, cb) ->
unless post.isDead or post.file.isDead
return cb post.file.URL + '?' + Date.now()
URL = Redirect.to 'file',
boardID: post.board.ID
filename: post.file.URL
if URL and (/^https:\/\//.test(URL) or location.protocol is 'http:')
return cb URL

View File

@ -125,8 +125,9 @@ ImageExpand =
thumb.parentNode.target = '_blank' thumb.parentNode.target = '_blank'
for eventName, cb of ImageExpand.videoCB for eventName, cb of ImageExpand.videoCB
$.off el, eventName, cb $.off el, eventName, cb
$.rm post.file.videoControls if post.file.videoControls
delete post.file.videoControls $.rm post.file.videoControls
delete post.file.videoControls
$.rmClass post.nodes.root, 'expanded-image' $.rmClass post.nodes.root, 'expanded-image'
$.rmClass thumb, 'expanding' $.rmClass thumb, 'expanding'
delete post.file.isExpanded delete post.file.isExpanded
@ -223,9 +224,8 @@ ImageExpand =
# Don't try to re-expand if it was already contracted. # Don't try to re-expand if it was already contracted.
return return
ImageExpand.contract post ImageExpand.contract post
ImageCommon.error @, post, return if ImageCommon.decodeError @, post
((URL) -> setTimeout ImageExpand.expand, 10 * $.SECOND, post, URL), ImageCommon.error post, 10 * $.SECOND, (URL) -> ImageExpand.expand post, URL
(-> setTimeout ImageExpand.expand, 10 * $.SECOND, post)
menu: menu:
init: -> init: ->

View File

@ -43,6 +43,5 @@ ImageHover =
error: -> error: ->
return unless doc.contains @ return unless doc.contains @
post = g.posts[@dataset.fullID] post = g.posts[@dataset.fullID]
ImageCommon.error @, post, return if ImageCommon.decodeError @, post
((URL) => @src = URL), ImageCommon.error post, 3 * $.SECOND, @src = URL
(=> setTimeout (=> @src = post.file.URL + '?' + Date.now()), 3 * $.SECOND)