11const MongoClient = require ( 'mongodb' ) . MongoClient ;
2+ const Raven = require ( 'raven' ) ;
23
34class 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