Permalink
Browse files

add a window.onerror handler to show client side errors in the consol…

…e while debugging
  • Loading branch information...
1 parent 06aecdd commit 33b22c64d13f3c83b4698a8d91dbc1f28fbd421b @kkaefer kkaefer committed Aug 9, 2011
Showing with 45 additions and 0 deletions.
  1. +9 −0 assets/debug.js
  2. +15 −0 servers/Core.bones
  3. +16 −0 servers/Debug.bones
  4. +5 −0 servers/Route.bones
View
@@ -0,0 +1,9 @@
+window.onerror = function(message, url, line) {
+ $.ajax('/api/Error', {
+ data: {
+ message: message,
+ url: url,
+ line: line
+ }
+ });
+};
View
@@ -1,3 +1,4 @@
+var env = process.env.NODE_ENV || 'development';
var middleware = require('..').middleware;
server = Bones.Server.extend({});
@@ -6,7 +7,21 @@ server.prototype.port = 3000;
server.prototype.initialize = function(app) {
this.port = app.config.port || this.port;
+
+ // Middleware provides body decoding, CSRF validation et al.
+ // Place other servers before this one ONLY when you intend to circumvent
+ // these safeguards.
this.use(new servers['Middleware'](app));
+
+ // Debugging server provides facilities for easier client side debugging.
+ if (env === 'development') {
+ this.use(new servers['Debug'](app));
+ }
+
+ // The Route server provides default routes for /api/Model as well as
+ // the /assets/bones routes.
this.use(new servers['Route'](app));
+
+ // The Asset server provides each plugin's asset folder at /asset/pluginname.
this.use(new servers['Asset'](app));
};
View
@@ -0,0 +1,16 @@
+var env = process.env.NODE_ENV || 'development';
+
+server = Bones.Server.extend({
+ initialize: function(app) {
+ _.bindAll(this, 'logError');
+ if (env === 'development') {
+ this.get('/api/Error', this.logError);
+ }
+ },
+
+ logError: function(req, res, next) {
+ console.error("Client Error: %s\n at %s:%d",
+ req.query.message, req.query.url, req.query.line);
+ res.send();
+ }
+});
View
@@ -1,3 +1,4 @@
+var env = process.env.NODE_ENV || 'development';
var headers = { 'Content-Type': 'application/json' };
server = Bones.Server.extend({});
@@ -27,6 +28,10 @@ server.prototype.assets = {
templates: new mirror([], options)
};
+if (env === 'development') {
+ server.prototype.assets.core.unshift(require.resolve('bones/assets/debug'));
+}
+
// TODO: This should be moved to the initialize method!
server.prototype.assets.all = new mirror([
server.prototype.assets.vendor,

0 comments on commit 33b22c6

Please sign in to comment.