Skip to content

Commit

Permalink
raven for exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
VibhorCodecianGupta authored and VibhorCodecianGupta committed Jun 11, 2018
1 parent a9b7d67 commit 917ffba
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
node_modules/
.DS_Store/
public_html/bower_components/
/secrets.json
secrets.json
npm-debug.log
newrelic_agent.log
7 changes: 4 additions & 3 deletions auth/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const models = require('../db/models');
const config = require('../config');
const uid = require('uid2')
const bearerStrategy = require('./strategies/bearerStrategy');

const Raven = require('raven');

passport.use('oneauth', new oneauthStrategy({
authorizationURL: 'https://account.codingblocks.com/oauth/authorize',
Expand Down Expand Up @@ -34,7 +34,8 @@ passport.use('oneauth', new oneauthStrategy({
).then(function (authtokenObject) {
return done(null, authtokenObject[0].get())
}).catch(function (err) {
console.log(err);
Raven.captureException(err)
return done(err, false);
})
}
else {
Expand Down Expand Up @@ -63,4 +64,4 @@ passport.deserializeUser(function (user, done) {
});
passport.use('bearer', bearerStrategy);

module.exports = passport;
module.exports = passport;
3 changes: 2 additions & 1 deletion auth/strategies/bearerStrategy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const BearerStrategy = require('passport-http-bearer').Strategy;
const models = require('./../../db/models');

const Raven = require('raven');

module.exports = new BearerStrategy(function (token, done) {

Expand All @@ -22,6 +22,7 @@ module.exports = new BearerStrategy(function (token, done) {
return done(null, false, {message: 'Could not authorize'});
}
}).catch(function (err) {
Raven.captureException(err)
return done(err, false);
});

Expand Down
4 changes: 2 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ switch (config.DEPLOY_CONFIG) {
break;

case 'localhost':
config.secrets = require('./secrets-sample')
config.secrets = require('./secrets')
config.db = config.secrets.DATABASE
config.clientId = config.secrets.ONEAUTH.CLIENT_ID;
config.clientSecret = config.secrets.ONEAUTH.CLIENT_SECRET;
Expand All @@ -45,4 +45,4 @@ config.SENTRY_DSN = process.env.SENTRY_DSN || config.secrets.SENTRY_DSN
config.NEW_RELIC_LICENSE_KEY = process.env.NEW_RELIC_LICENSE_KEY || config.secrets.NEW_RELIC_LICENSE_KEY


exports = module.exports = config
exports = module.exports = config
30 changes: 20 additions & 10 deletions db/actions/batches.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*
* Created by tech4GT on 8/25/17.
*/
const Raven = require('raven')
const models = require('../models')
module.exports = {

Expand All @@ -23,7 +24,8 @@ module.exports = {
}).then(function (data) {
done(null, data)
}).catch(function (err) {
if (err) done(err);
Raven.captureException(err)
if (err) done(err)
});
},
getAll: function (conditions, done) {
Expand All @@ -35,7 +37,8 @@ module.exports = {

done(null, data)
}).catch(function (err) {
if (err) done(err);
Raven.captureException(err)
if (err) done(err)
});
},
search: function (id, done) {
Expand All @@ -50,7 +53,8 @@ module.exports = {
}).then(function (data) {
done(null, data);
}).catch(function (err) {
if (err) done(err);
Raven.captureException(err)
if (err) done(err)
});
},
edit: function (id, obj, done) {
Expand All @@ -65,10 +69,12 @@ module.exports = {
data.update(obj).then(function (resData) {
done(null, resData);
}).catch(function (err) {
if (err) done(err);
Raven.captureException(err)
if (err) done(err)
})
}).catch(function (err) {
if (err) done(err);
Raven.captureException(err)
if (err) done(err)
});
},
archiveBatch: function (id, done) {
Expand All @@ -85,10 +91,12 @@ module.exports = {
}).then(function (resData) {
done(null, resData);
}).catch(function (err) {
if (err) done(err);
Raven.captureException(err)
if (err) done(err)
})
}).catch(function (err) {
if (err) done(err);
Raven.captureException(err)
if (err) done(err)
});
},
deleteBatch: function (id, done) {
Expand All @@ -99,7 +107,8 @@ module.exports = {
}).then(function (data) {
done(null, data)
}).catch(function (err) {
if (err) done(err);
Raven.captureException(err)
if (err) done(err)
});
}
,
Expand All @@ -112,7 +121,8 @@ module.exports = {
}).then(function (data) {
done(null, data)
}).catch(function (err) {
if (err) done(err);
Raven.captureException(err)
if (err) done(err)
});
}
}
}
33 changes: 20 additions & 13 deletions db/actions/centres.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Created by abhishekyadav on 25/08/17.
*/
const models = require('../models')
const Raven = require('raven')

module.exports = {
createNew: function (name, head, phone, done) {
Expand All @@ -12,14 +13,16 @@ module.exports = {
}).then(function (data) {
done(null, data)
}).catch(function (err) {
if (err) done(err);
Raven.captureException(err)
if (err) done(err)
});
},
getAll: function (done) {
models.Centres.findAll({order: ['id']}).then(function (data) {
done(null, data)
}).catch(function (err) {
if (err) done(err);
Raven.captureException(err)
if (err) done(err)
});
},
search: function (id, done) {
Expand All @@ -30,7 +33,8 @@ module.exports = {
}).then(function (data) {
done(null, data)
}).catch(function (err) {
if (err) done(err);
Raven.captureException(err)
if (err) done(err)
});
},
edit: function (id, obj, done) {
Expand All @@ -45,10 +49,12 @@ module.exports = {
data.update(obj).then(function (resData) {
done(null, resData);
}).catch(function (err) {
if (err) done(err);
Raven.captureException(err)
if (err) done(err)
})
}).catch(function (err) {
if (err) done(err);
Raven.captureException(err)
if (err) done(err)
});
},
deleteCentre: function (id, done) {
Expand All @@ -59,7 +65,8 @@ module.exports = {
}).then(function (data) {
done(null, data)
}).catch(function (err) {
if (err) done(err);
Raven.captureException(err)
if (err) done(err)
});
},
getBatches: function (id, done) {
Expand All @@ -72,8 +79,8 @@ module.exports = {
}).then(function (data) {
done(null, data);
}).catch(function (err) {
if (err)
done(err);
Raven.captureException(err)
if (err) done(err)
})
},
getActiveBatches: function (id, done) {
Expand All @@ -87,8 +94,8 @@ module.exports = {
}).then(function (data) {
done(null, data);
}).catch(function (err) {
if (err)
done(err);
Raven.captureException(err)
if (err) done(err)
})
},
getRooms: function (id, done) {
Expand All @@ -100,8 +107,8 @@ module.exports = {
}).then(function (data) {
done(null, data);
}).catch(function (err) {
if (err)
done(err);
Raven.captureException(err)
if (err) done(err)
})
}
}
}
29 changes: 18 additions & 11 deletions db/actions/courses.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Created by tech4GT on 8/25/17.
*/

const Raven = require('raven')
const models = require('../models')

module.exports = {
Expand All @@ -14,14 +14,16 @@ module.exports = {
}).then(function (data) {
done(null, data)
}).catch(function (err) {
if (err) done(err);
Raven.captureException(err)
if (err) done(err)
});
},
getAll: function (done) {
models.Courses.findAll({order: ['id']}).then(function (data) {
done(null, data)
}).catch(function (err) {
if (err) done(err);
Raven.captureException(err)
if (err) done(err)
});
},
search: function (id, done) {
Expand All @@ -32,7 +34,8 @@ module.exports = {
}).then(function (data) {
done(null, data)
}).catch(function (err) {
if (err) done(err);
Raven.captureException(err)
if (err) done(err)
});
},
edit: function (id, obj, done) {
Expand All @@ -47,10 +50,12 @@ module.exports = {
data.update(obj).then(function (resData) {
done(null, resData);
}).catch(function (err) {
if (err) done(err);
Raven.captureException(err)
if (err) done(err)
})
}).catch(function (err) {
if (err) done(err);
Raven.captureException(err)
if (err) done(err)
});
},
deleteCourse: function (id, done) {
Expand All @@ -61,7 +66,8 @@ module.exports = {
}).then(function (data) {
done(null, data)
}).catch(function (err) {
if (err) throw err;
Raven.captureException(err)
if (err) done(err)
});
},
getlectures: function (id, done) {
Expand All @@ -86,7 +92,8 @@ module.exports = {
}
done(arr);
}).catch(function (err) {
if (err) done(err);
Raven.captureException(err)
if (err) done(err)
});
},
getBatches: function (id, done) {
Expand All @@ -98,8 +105,8 @@ module.exports = {
}).then(function (data) {
done(null, data);
}).catch(function (err) {
if (err)
done(err);
Raven.captureException(err)
if (err) done(err)
})
}
}
}
Loading

0 comments on commit 917ffba

Please sign in to comment.