Answer the question
In order to leave comments, you need to log in
Reject from switch. The log is reject'a is not present. How to reject from switch?
Dear gurus, maybe someone can answer my questions.
return new Promise(function(resolve, reject){
Object.keys(schemaPaths).forEach(function(path){
switch(schemaPaths[path].instance){
case 'String' :
cs(schemaPaths[path], data[path]).catch(function(e){
console.error(e);
reject(e);
});
break;
default :
reject('default');
break;
};
});
resolve()
});
cs
returns a Promise, more precisely Promise.reject(). Then it displays an error in the console and does further reject. case 'String' :
, but for some reason it first goes to default.
and there it will already execute reject(). default :
reject('default');
break;
};
return new Promise(function(resolve, reject){
Object.keys(schemaPaths).forEach(function(path){
switch(schemaPaths[path].instance){
case 'String' :
cs(schemaPaths[path], data[path]).catch(function(e){
console.error(e);
reject(e);
});
};
});
resolve()
});
If-Else
everything and it works as it should. But the question remains, but there is no solution. Answer the question
In order to leave comments, you need to log in
return new Promise(function(resolve, reject){
Object.keys(schemaPaths).forEach(function(path){
switch(schemaPaths[path].instance){
case 'String' :
return cs(schemaPaths[path], data[path]).catch(function(e){
console.error(e);
reject(e);
});
break;
default :
return reject('default');
break;
};
});
resolve()
});
function wtf(){
var promise;
Object.keys(schemaPaths).forEach(function(path){
switch(schemaPaths[path].instance){
case 'String' :
if(!promise){
promise = cs(schemaPaths[path], data[path]).catch(function(e){
console.error(e);
return Promise.reject(e);
});
}
break;
default :
if(!promise) promise = Promise.reject('default');
break;
};
});
return promise;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question