@@ -16,6 +16,7 @@ import type {Global} from 'types/Global';
16
16
17
17
import isGeneratorFn from 'is-generator-fn' ;
18
18
import co from 'co' ;
19
+ import checkIsError from './is_error' ;
19
20
20
21
function isPromise ( obj ) {
21
22
return obj && typeof obj . then === 'function' ;
@@ -34,14 +35,23 @@ function promisifyLifeCycleFunction(originalFn, env) {
34
35
return originalFn . call ( env , fn , timeout ) ;
35
36
}
36
37
38
+ const extraError = new Error ( ) ;
39
+
37
40
// We make *all* functions async and run `done` right away if they
38
41
// didn't return a promise.
39
42
const asyncFn = function ( done ) {
40
43
const wrappedFn = isGeneratorFn ( fn ) ? co . wrap ( fn ) : fn ;
41
44
const returnValue = wrappedFn . call ( { } ) ;
42
45
43
46
if ( isPromise ( returnValue ) ) {
44
- returnValue . then ( done . bind ( null , null ) , done . fail ) ;
47
+ returnValue . then ( done . bind ( null , null ) , error => {
48
+ const { isError, message} = checkIsError ( error ) ;
49
+
50
+ if ( message ) {
51
+ extraError . message = message ;
52
+ }
53
+ done . fail ( isError ? error : extraError ) ;
54
+ } ) ;
45
55
} else {
46
56
done ( ) ;
47
57
}
@@ -67,12 +77,21 @@ function promisifyIt(originalFn, env) {
67
77
return originalFn . call ( env , specName , fn , timeout ) ;
68
78
}
69
79
80
+ const extraError = new Error ( ) ;
81
+
70
82
const asyncFn = function ( done ) {
71
83
const wrappedFn = isGeneratorFn ( fn ) ? co . wrap ( fn ) : fn ;
72
84
const returnValue = wrappedFn . call ( { } ) ;
73
85
74
86
if ( isPromise ( returnValue ) ) {
75
- returnValue . then ( done . bind ( null , null ) , done . fail ) ;
87
+ returnValue . then ( done . bind ( null , null ) , error => {
88
+ const { isError, message} = checkIsError ( error ) ;
89
+
90
+ if ( message ) {
91
+ extraError . message = message ;
92
+ }
93
+ done . fail ( isError ? error : extraError ) ;
94
+ } ) ;
76
95
} else if ( returnValue === undefined ) {
77
96
done ( ) ;
78
97
} else {
0 commit comments