I have a code example in this format:
someFunction(data)
.then(response => {
return response.text();
}).then(text => {
console.log(text)
}).catch(err => {
console.error(err)
});
I want to stuff this into my own function and call it through out my code.
let result = await callSnippet(myData);
This is what I've been doing... Is this the best way? Should I be using a promise here?
async callSnippet(data) {
let response = null
await someFunction(data)
.then( d=> { return d.text(); })
.then( d=> { response = {success:true, result:d }; })
.catch( d=> { response = {success:false, result:d }; })
return response;
}