Let's try a heads-up whenever there's a JS error.

This commit is contained in:
Nick Winter 2014-07-13 08:37:39 -07:00
parent bbc1228c9c
commit 8a7e7e82a0

View file

@ -18,6 +18,7 @@ definitionSchemas =
'misc': require './schemas/definitions/misc'
init = ->
watchForErrors()
path = document.location.pathname
testing = path.startsWith '/test'
demoing = path.startsWith '/demo'
@ -79,3 +80,16 @@ initializeServices = ->
for service in services
service = require service
service()
watchForErrors = ->
currentErrors = 0
window.onerror = (msg, url, line, col, error) ->
return if currentErrors >= 3
return unless me.isAdmin() or document.location.href.search(/codecombat.com/) is -1 or document.location.href.search(/\/editor\//) isnt -1
++currentErrors
msg = "Error: #{msg}<br>Check the JS console for more."
#msg += "\nLine: #{line}" if line?
#msg += "\nColumn: #{col}" if col?
#msg += "\nError: #{error}" if error?
#msg += "\nStack: #{stack}" if stack = error?.stack
noty text: msg, layout: 'topCenter', type: 'error', killer: false, timeout: 5000, dismissQueue: true, maxVisible: 3, callback: {onClose: -> --currentErrors}