Nice, I dig it! Thanks Bibek Kakati!
I’d like to chime in with a minor yet potential improvement.
const getData = async () => {
try {
const result = await methodCall();
return { result };
} catch(error) {
return { error };
}
}
const { result, error } = getData();
if (error) {
// …
}
IMO returning an object (and destructuring both result and error) is way more readable & explicit.