@@ -353,7 +353,10 @@ class DSRethinkDBAdapter {
353353 options = options || { }
354354 return this . waitForTable ( resourceConfig . table || underscore ( resourceConfig . name ) , options ) . then ( ( ) => {
355355 return this . r . db ( options . db || this . defaults . db ) . table ( resourceConfig . table || underscore ( resourceConfig . name ) ) . insert ( attrs , { returnChanges : true } ) . run ( )
356- } ) . then ( cursor => cursor . changes [ 0 ] . new_val )
356+ } ) . then ( cursor => {
357+ this . _handleErrors ( cursor )
358+ return cursor . changes [ 0 ] . new_val
359+ } )
357360 }
358361
359362 update ( resourceConfig , id , attrs , options ) {
@@ -362,6 +365,7 @@ class DSRethinkDBAdapter {
362365 return this . waitForTable ( resourceConfig . table || underscore ( resourceConfig . name ) , options ) . then ( ( ) => {
363366 return this . r . db ( options . db || this . defaults . db ) . table ( resourceConfig . table || underscore ( resourceConfig . name ) ) . get ( id ) . update ( attrs , { returnChanges : true } ) . run ( )
364367 } ) . then ( cursor => {
368+ this . _handleErrors ( cursor )
365369 if ( cursor . changes && cursor . changes . length && cursor . changes [ 0 ] . new_val ) {
366370 return cursor . changes [ 0 ] . new_val
367371 } else {
@@ -377,6 +381,7 @@ class DSRethinkDBAdapter {
377381 return this . waitForTable ( resourceConfig . table || underscore ( resourceConfig . name ) , options ) . then ( ( ) => {
378382 return this . filterSequence ( this . selectTable ( resourceConfig , options ) , params ) . update ( attrs , { returnChanges : true } ) . run ( )
379383 } ) . then ( cursor => {
384+ this . _handleErrors ( cursor )
380385 if ( cursor && cursor . changes && cursor . changes . length ) {
381386 let items = [ ]
382387 cursor . changes . forEach ( change => items . push ( change . new_val ) )
@@ -401,6 +406,15 @@ class DSRethinkDBAdapter {
401406 return this . filterSequence ( this . selectTable ( resourceConfig , options ) , params ) . delete ( ) . run ( )
402407 } ) . then ( ( ) => undefined )
403408 }
409+
410+ _handleErrors ( cursor ) {
411+ if ( cursor && cursor . errors > 0 ) {
412+ if ( cursor . first_error ) {
413+ throw new Error ( cursor . first_error )
414+ }
415+ throw new Error ( 'Unknown RethinkDB Error' )
416+ }
417+ }
404418}
405419
406420module . exports = DSRethinkDBAdapter
0 commit comments