Skip to content

Instantly share code, notes, and snippets.

@ika18
Created July 29, 2013 06:00
Show Gist options
  • Save ika18/6102391 to your computer and use it in GitHub Desktop.
Save ika18/6102391 to your computer and use it in GitHub Desktop.
an error handling in troopjs
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