diff --git a/app/initialize.coffee b/app/initialize.coffee index 5462242f4..b2d69ee13 100644 --- a/app/initialize.coffee +++ b/app/initialize.coffee @@ -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}
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}