Is it possible to use a Proxy to wrap calls to async methods on an object with error handling?
I tried the code below, but the catch isn't executing when errors are occurring in the proxied method.
const implementation = {
// proxied async methods here
}
const proxy = new Proxy(implementation, {
get: (target, prop, reciever) => {
try {
return Reflect.get(target, prop, reciever)
}
catch (error) {
console.log('Error:')
console.error(error)
}
}
})
My goal was to avoid implementing error-handling in each proxied method.