I find myself facing a challenging scenario involving the use of promises (then|catch) for error handling, while also awaiting code cleanliness. Here's what I'm currently dealing with:
let rules:Rules = await elb.describeRules(params).promise().then(_handleSuccess).catch(_handleError);
The error handler function is:
function _handleError(e:AWSError) {
console.error(`Error getting rules info - [${e.code}] ${e.message}`);
throw(e)
}
The success handler function is:
function _handleSuccess(res:DescribeRulesOutput) {
console.log(`Get rules info: ${JSON.stringify(res.Rules,null,4)}`);
return res.Rules ;
}
Since my error handler always rethrows, theoretically I should not receive a response. However, my IDE (VSCode) displays the following message:
Type 'void | Rules' is not assignable to type 'Rules'.
Type 'void' is not assignable to type 'Rules'.ts
Considering this issue, if I change let rules:Rules|void
everything works fine. But my question is, is this considered good practice?