Skip to content

Commit d08a002

Browse files
committed
added sentry exception tracking
1 parent 7619ed9 commit d08a002

File tree

7 files changed

+132
-13
lines changed

7 files changed

+132
-13
lines changed

bookmancy/main.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const bookmancy = require('bookmancy');
2+
const Raven = require('raven');
23
const slackResponder = require('./slack-responder');
34
const confirmMessage = require('./confirmation-messages');
45
const is = {
@@ -21,14 +22,22 @@ module.exports = c => {
2122
year: format && !isNaN(format) ? format : !isNaN(year) && year,
2223
format: isNaN(year) ? year : format
2324
};
24-
25+
2526
bookmancy.abe.searchWithUrlInResponse(query)
2627
.then(({results, url}) => {
2728
const searchTitle = messagePieces.join(' - ');
2829
b.reply(m, slackResponder(searchTitle, url, results));
2930
})
3031
.catch(err => {
31-
console.error(err.message || err.toString(), err.stack);
32+
Raven.context(() => {
33+
Raven.setContext({
34+
module: {
35+
name: 'bookmancy',
36+
cmd: m.text
37+
}
38+
});
39+
Raven.captureException(err);
40+
})
3241
b.reply(m, {
3342
response_type: 'ephemeral',
3443
text: 'There was a problem processing your search. Try again soon.'
@@ -40,7 +49,8 @@ module.exports = c => {
4049
const isLive = is.live(command);
4150
const query = command.replace(isLive ? /live/i : /sold/i, '').trim();
4251
return bookmancy.ebay[`search${isLive ? 'Live' : 'Sold'}Listings`](query)
43-
.then(r => b.reply(m, slackResponder(query, '', r, true)));
52+
.then(r => b.reply(m, slackResponder(query, '', r, true)))
53+
.catch(err => Raven.captureException(err));
4454
}
4555
});
4656
};

fired/fired.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const getDom = require('../utils/getDom');
22
const SimpleDb = require('../utils/simple-db');
33
const ROSTER_URL = 'https://consumeraffairs.com/about/staff/';
44
const COLL_NAME = 'employees';
5+
const Raven = require('raven');
56

67
class Fired extends SimpleDb {
78
constructor() {
@@ -24,7 +25,7 @@ class Fired extends SimpleDb {
2425
fired: false
2526
}));
2627
if (!roster || !roster.length) {
27-
throw new Error('no employee data found on domQuery');
28+
Raven.captureException(new Error('FIRED: no employee data found on domQuery'));
2829
}
2930
return roster;
3031
});
@@ -39,7 +40,7 @@ class Fired extends SimpleDb {
3940
if (!oldRoster.length) {
4041
this.saveMany(nowRoster)
4142
.then(() => console.log('No news. Saved current roster for future comparisons.'))
42-
.catch(err => console.error(err));
43+
.catch(err => Raven.captureException(err));
4344
return [];
4445
} else {
4546
// employees that aren't found in the newly loaded roster
@@ -56,7 +57,7 @@ class Fired extends SimpleDb {
5657

5758
if (newHires.length) {
5859
this.saveMany(newHires)
59-
.catch(err => console.log('problem saving yo'));
60+
.catch(err => Raven.captureException(err));
6061
}
6162
if (newFires.length) {
6263
const wait = newFires

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
require('dotenv').config();
2+
const Raven = require('raven');
3+
Raven.config(process.env.SENTRY_URL).install();
24
const Botkit = require('botkit/lib/Botkit.js');
35
const os = require('os');
46

57
if (!process.env.token) {
68
console.log('Error: Specify token in environment');
9+
Raven.captureException(new Error('no token in environment'));
710
process.exit(1);
811
}
912
const controller = Botkit.slackbot({debug: false});

package-lock.json

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"dotenv": "^4.0.0",
1919
"jsdom": "^9.9.1",
2020
"momentjs": "^2.0.0",
21-
"mongodb": "^2.2.29"
21+
"mongodb": "^2.2.29",
22+
"raven": "^2.4.0"
2223
},
2324
"devDependencies": {
2425
"jest": "^20.0.4"

utils/getDom.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
const jsdom = require('jsdom');
2+
const Raven = require('raven');
23

34
module.exports = url => {
45
return new Promise((resolve, reject) => {
56
jsdom.env(url, (err, w) => {
67
if (!err && !!w) {
78
resolve(w.document);
89
} else {
10+
Raven.captureException(err);
911
reject(err);
1012
}
1113
});

utils/simple-db.js

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const MongoClient = require('mongodb').MongoClient;
2+
const Raven = require('raven');
23

34
class SimpleDb {
45
constructor(collectionName) {
@@ -15,33 +16,99 @@ class SimpleDb {
1516

1617
getCollection() {
1718
return this.getDb()
18-
.then(d => d.collection(this.collection));
19+
.then(d => d.collection(this.collection))
20+
.catch(err => {
21+
Raven.context(() => {
22+
Raven.setContext({
23+
module: {
24+
name: 'db',
25+
cmd: 'get-collection'
26+
}
27+
});
28+
Raven.captureException(err);
29+
});
30+
});
1931
}
2032

2133
getDocumentById(id) {
2234
return this.getCollection()
23-
.then(c => c.findOne({_id: id}));
35+
.then(c => c.findOne({_id: id}))
36+
.catch(err => {
37+
Raven.context(() => {
38+
Raven.setContext({
39+
module: {
40+
name: 'db',
41+
cmd: 'get-doc-by-id'
42+
}
43+
});
44+
Raven.captureException(err);
45+
});
46+
});
2447
}
2548

2649
saveDocument(doc, searchPredicate) {
2750
searchPredicate = searchPredicate || {_id: doc._id};
2851
return this.getCollection()
29-
.then(c => c.update(searchPredicate, doc));
52+
.then(c => c.update(searchPredicate, doc))
53+
.catch(err => {
54+
Raven.context(() => {
55+
Raven.setContext({
56+
module: {
57+
name: 'db',
58+
cmd: 'save-doc'
59+
}
60+
});
61+
Raven.captureException(err);
62+
});
63+
});
3064
}
3165

3266
saveMany(docs) {
3367
return this.getCollection()
34-
.then(c => c.insertMany(docs));
68+
.then(c => c.insertMany(docs))
69+
.catch(err => {
70+
Raven.context(() => {
71+
Raven.setContext({
72+
module: {
73+
name: 'db',
74+
cmd: 'save-many'
75+
}
76+
});
77+
Raven.captureException(err);
78+
});
79+
});
3580
}
3681

3782
getAllDocuments() {
3883
return this.getCollection()
39-
.then(c => c.find().toArray());
84+
.then(c => c.find().toArray())
85+
.catch(err => {
86+
Raven.context(() => {
87+
Raven.setContext({
88+
module: {
89+
name: 'db',
90+
cmd: 'get-all-docs'
91+
}
92+
});
93+
Raven.captureException(err);
94+
});
95+
});
4096
}
4197

4298
removeAllDocuments(template) {
4399
return this.getCollection()
44-
.then(c => c.remove({}));
100+
.then(c => c.remove({}))
101+
.catch(err => {
102+
Raven.context(() => {
103+
Raven.setContext({
104+
module: {
105+
name: 'db',
106+
cmd: 'remove-all-docs'
107+
}
108+
});
109+
Raven.captureException(err);
110+
});
111+
});
45112
}
46113
}
47114

0 commit comments

Comments
 (0)