You can define you own custom error. For example :
function CustomError(errorText){
this.error = errorText;
}
Modify your functions. Add catch block for each Promise returned from function:
function p(){
return new Promise(function(resolve, reject){
//Your functionality here
})
.catch(function(error){
Promise.reject(new CustomError('f1')));
})
}
And so on: f2, f3, f4
And your catch block will be:
.catch((err) => {
if(err instanceof CustomError){
HandleCustomError(err);
} else {
//Some another error is happen
}
})
And you custom error handler will be something like that:
function HandleCustomError(customError){
switch(customError.error){
case 'f1':
//handle f1
break;
case 'f2':
//handle f2
break;
...
}
}