I am running a query to return some data
async function getIngress(namespace) {
try {
const result = await k8sIngressApi.listNamespacedIngress(namespace, true);
const resultSpec = result.body.items[0].spec;
return resultSpec;
} catch (e) {
throw new Error(e);
}
}
How do I check if resultSpec is undefined and if so throw and error and stop executing?
I have tried
return resultSpec || throw new Error() however get syntax errors when I try that.
if(!resultSpec) throw new Error()?throwis a statement, not an expression.return resultSpec || new Error();if you actually want to return an error like your title says, but your question body says you want to throw the error and stop executing, so you just need to determine if the variable is undefined (which can be answered by the linked question's answers) and throw an error.