Created
August 20, 2018 17:55
-
-
Save enkot/d4c443b16cd7c7bf7ccffc0bcb266d51 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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