-
-
Save ika18/6102391 to your computer and use it in GitHub Desktop.
an error handling in troopjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(['jquery', | |
'troopjs-core/component/service', | |
'config'], function RouteService($, Service, config) { | |
'use strict'; | |
var URL = '/rest/data/errorlog'; | |
function log(msg, stack) { | |
if (!config.debug) { | |
var data = { | |
context: { | |
url: window.location.href | |
}, | |
message: msg, | |
exc_text: stack || '' | |
}; | |
$.ajax({ | |
url: URL, | |
data: { | |
data: JSON.stringify(data) | |
}, | |
type: 'post' | |
}); | |
} | |
} | |
return Service.extend({ | |
'sig/initialize': function (signal, deferred) { | |
window.onerror = function (msg, url, line) { | |
log(msg); | |
return true; | |
}; | |
deferred.resolve(); | |
}, | |
'hub:memory/error/log': function (topic, url, msg, stack) { | |
log(msg, stack); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment