Trying to combine response either (success or failure) both scenario with below code its returning empty object because one of the handler has an error.
1- How to combine responses using Promise.all if one promise fails i want to have that promise error part of final response?
2- what would be right approach to have this problem resolved.
main.ts
private async execute(@Request() request: ExpressRequest): Promise < any > {
let _combineData: any = [];
const accountBalanceRequest = request.body.getAccountBalanceRequest;
try {
const _data1 = await this.Handler1(accountBalanceRequest);
const _data2 = await this.Handler2(request);
const combinedResponses = await Promise.all([_data1,_data2].map((callback) => callback(val))
.then(values => {
combineData = values;
})
.catch(err => {
console.log(err);
}); _
}
catch (err) {
return err;
}
return _combineData;
}
thats how i wanted to build the response
details: [{
success response from first promise handler
}, {
error from 2n d promise handler
}]