Skip to content

Commit cf46cfa

Browse files
committed
add error handler
1 parent 5ecb4dc commit cf46cfa

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

lib/flow.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,42 @@ var Flow = function (){
9797

9898
Flow.prototype = {
9999

100+
/**
101+
* Default error handler.
102+
* @private
103+
* @this {Flow}
104+
* @param {Error} err Error to throw.
105+
*/
106+
_error : function ( err ){
107+
throw err;
108+
},
109+
110+
111+
112+
/**
113+
* Check if the stack handler is the `next` handler.
114+
* @private
115+
* @this {Flow}
116+
* @param {String} str The handler to be check.
117+
*/
100118
_is_next : function ( str ){
101119
return /self\[ '_' \+ next_type \]\.apply\( self, slice\.call\( arguments \)\);/g.test( str );
102120
},
103121

122+
123+
104124
/**
105125
* Call the current series function and remove it.
106126
* @private
107127
* @this {Flow}
108128
* @param {Array} args Arguments to be passed to the current series function.
109129
*/
110130
_run_series : function ( args ){
111-
this._series.shift().apply( this, args );
131+
try{
132+
this._series.shift().apply( this, args );
133+
}catch( err ){
134+
this._error( err );
135+
}
112136
},
113137

114138

@@ -145,7 +169,6 @@ Flow.prototype = {
145169
* @param {Array} args Arguments to be added to the current parallel function.
146170
*/
147171
_run_parallel : function ( args ){
148-
149172
var self = this;
150173
var parallel_args = this._parallel_args.shift();
151174
var args_form_last_task = args;
@@ -357,6 +380,12 @@ Flow.prototype = {
357380
return this;
358381
},
359382

383+
error : function ( callback ){
384+
this._error = callback;
385+
386+
return this;
387+
},
388+
360389

361390

362391
/**

0 commit comments

Comments
 (0)