ts-ioc-container
Version:
Fast, lightweight TypeScript dependency injection container with a clean API, scoped lifecycles, decorators, tokens, hooks, lazy injection, customizable providers, and no global container objects.
25 lines (24 loc) • 817 B
JavaScript
export const handleAsyncError = (errorHandler) => (target, propertyKey, descriptor) => {
const originalMethod = descriptor.value;
descriptor.value = async function (...args) {
try {
return await originalMethod.apply(this, args);
}
catch (e) {
errorHandler(e, { target: target.constructor.name, method: propertyKey });
}
};
return descriptor;
};
export const handleError = (errorHandler) => (target, propertyKey, descriptor) => {
const originalMethod = descriptor.value;
descriptor.value = function (...args) {
try {
return originalMethod.apply(this, args);
}
catch (e) {
errorHandler(e, { target: target.constructor.name, method: propertyKey });
}
};
return descriptor;
};