File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -682,7 +682,7 @@ class QueryBuilder extends QueryBuilderBase {
682
682
const result = await doExecute ( builder ) ;
683
683
return await afterExecute ( builder , result ) ;
684
684
} catch ( error ) {
685
- await handleExecuteError ( builder , error ) ;
685
+ return await handleExecuteError ( builder , error ) ;
686
686
}
687
687
}
688
688
Original file line number Diff line number Diff line change @@ -654,6 +654,41 @@ describe('QueryBuilder', () => {
654
654
} ) ;
655
655
} ) ;
656
656
657
+ it ( 'throwing at any phase should call the onError hook' , done => {
658
+ let called = false ;
659
+ QueryBuilder . forClass ( TestModel )
660
+ . runBefore ( function ( result , builder ) {
661
+ throw new Error ( ) ;
662
+ } )
663
+ . onError ( function ( err , builder ) {
664
+ called = true ;
665
+ } )
666
+ . then ( ( ) => {
667
+ expect ( called ) . to . equal ( true ) ;
668
+ done ( ) ;
669
+ } )
670
+ . catch ( err => {
671
+ done ( err ) ;
672
+ } ) ;
673
+ } ) ;
674
+
675
+ it ( 'any return value from onError should be the result of the query' , done => {
676
+ QueryBuilder . forClass ( TestModel )
677
+ . runBefore ( function ( result , builder ) {
678
+ throw new Error ( ) ;
679
+ } )
680
+ . onError ( function ( err , builder ) {
681
+ return 'my custom error' ;
682
+ } )
683
+ . then ( result => {
684
+ expect ( result ) . to . equal ( 'my custom error' ) ;
685
+ done ( ) ;
686
+ } )
687
+ . catch ( err => {
688
+ done ( err ) ;
689
+ } ) ;
690
+ } ) ;
691
+
657
692
it ( 'should call run* methods in the correct order' , done => {
658
693
mockKnexQueryResults = [ 0 ] ;
659
694
You can’t perform that action at this time.
0 commit comments