Make connection error messages consistent, and always retry on connection error.

This commit is contained in:
ccd0 2017-02-06 18:52:23 -08:00
parent 626e39bd15
commit e4a00d3b0c

View File

@ -241,6 +241,13 @@ QR =
notif.close() notif.close()
, 7 * $.SECOND , 7 * $.SECOND
connectionError: ->
$.el 'span',
<%= html(
'Connection error while posting. ' +
'[<a href="' + meta.faq + '#connection-errors" target="_blank">More info</a>]'
) %>
notifications: [] notifications: []
cleanNotifications: -> cleanNotifications: ->
@ -651,16 +658,14 @@ QR =
withCredentials: true withCredentials: true
onload: QR.response onload: QR.response
onerror: -> onerror: ->
# Connection error # On connection error, the post most likely didn't go through.
# If the post did go through, it should be stopped by the duplicate reply cooldown.
delete QR.req delete QR.req
post.unlock() post.unlock()
QR.cooldown.auto = false QR.cooldown.auto = true
QR.cooldown.addDelay post, 2
QR.status() QR.status()
QR.error $.el 'span', QR.error QR.connectionError()
<%= html(
'Connection error while posting. ' +
'[<a href="' + meta.faq + '#connection-errors" target="_blank">More info</a>]'
) %>
extra = extra =
form: $.formData formData form: $.formData formData
if Conf['Show Upload Progress'] if Conf['Show Upload Progress']
@ -698,13 +703,13 @@ QR =
resDoc = req.response resDoc = req.response
if (err = resDoc.getElementById 'errmsg') # error! if (err = resDoc.getElementById 'errmsg') # error!
$('a', err)?.target = '_blank' # duplicate image link $('a', err)?.target = '_blank' # duplicate image link
else if resDoc.title isnt 'Post successful!' else if (connErr = resDoc.title isnt 'Post successful!')
err = 'Connection error with sys.4chan.org.' err = QR.connectionError()
else if req.status isnt 200 else if req.status isnt 200
err = "Error #{req.statusText} (#{req.status})" err = "Error #{req.statusText} (#{req.status})"
if err if err
if /captcha|verification/i.test(err.textContent) or err is 'Connection error with sys.4chan.org.' if /captcha|verification/i.test(err.textContent) or connErr
# Remove the obnoxious 4chan Pass ad. # Remove the obnoxious 4chan Pass ad.
if /mistyped/i.test err.textContent if /mistyped/i.test err.textContent
err = 'You mistyped the CAPTCHA, or the CAPTCHA malfunctioned.' err = 'You mistyped the CAPTCHA, or the CAPTCHA malfunctioned.'
@ -712,9 +717,10 @@ QR =
err = 'This CAPTCHA is no longer valid because it has expired.' err = 'This CAPTCHA is no longer valid because it has expired.'
# Something must've gone terribly wrong if you get captcha errors without captchas. # Something must've gone terribly wrong if you get captcha errors without captchas.
# Don't auto-post indefinitely in that case. # Don't auto-post indefinitely in that case.
QR.cooldown.auto = QR.captcha.isEnabled or err is 'Connection error with sys.4chan.org.' QR.cooldown.auto = QR.captcha.isEnabled or connErr
# Too many frequent mistyped captchas will auto-ban you! # Too many frequent mistyped captchas will auto-ban you!
# On connection error, the post most likely didn't go through. # On connection error, the post most likely didn't go through.
# If the post did go through, it should be stopped by the duplicate reply cooldown.
QR.cooldown.addDelay post, 2 QR.cooldown.addDelay post, 2
else if err.textContent and (m = err.textContent.match /(?:(\d+)\s+minutes?\s+)?(\d+)\s+second/i) and !/duplicate|hour/i.test(err.textContent) else if err.textContent and (m = err.textContent.match /(?:(\d+)\s+minutes?\s+)?(\d+)\s+second/i) and !/duplicate|hour/i.test(err.textContent)
QR.cooldown.auto = !/have\s+been\s+muted/i.test(err.textContent) QR.cooldown.auto = !/have\s+been\s+muted/i.test(err.textContent)