I've got two files containing asynchronous calls, wrapped in try/catches:
index.js
const fetchData = async () => {
try {
const data = await Service.getData()
} catch (e) {
// do some error handling
}
}
Service.js
const Service = {
getData: async () => {
try {
const data = await callApi()
} catch (e) {
// do some more error handling
}
}
}
Is the try/catch necessary within fetchData(), since there's already a try/catch in getData()? i.e., is it enough to refactor like so...
const fetchData = async () => {
const data = await Service.getData()
}
...while letting the service method do all the error handling?
I know this may be a simple question of how to scaffold error handling and personal preference, but I'm mostly looking for what others would implement to reduce boilerplate code