Skip to content

Instantly share code, notes, and snippets.

@enkot
Created August 20, 2018 17:55
Show Gist options
  • Save enkot/d4c443b16cd7c7bf7ccffc0bcb266d51 to your computer and use it in GitHub Desktop.
Save enkot/d4c443b16cd7c7bf7ccffc0bcb266d51 to your computer and use it in GitHub Desktop.
function Catch(localHandler) {
return function(target, key, descriptor) {
const originalMethod = descriptor.value
descriptor.value = async function(...args) {
try {
return await originalMethod.apply(this, args)
} catch (error) {
const { handler } = catchDecoratorStore
if (localHandler) {
localHandler.call(null, error, this)
} else if(handler) {
handler.call(null, error, this)
} else {
console.warn(error.message)
}
}
}
return descriptor
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment