UNPKG

@httpc/kit

Version:

httpc toolbox for building function-based API with minimal code and end-to-end type safety

16 lines (15 loc) 563 B
export function Catch(defaultValue) { return (target, key, descriptor) => { const original = descriptor.value; descriptor.value = async function (...args) { try { return await original.apply(this, args); } catch (ex) { this.logger?.error(`Catch ${target.constructor.name}.${key.toString()}\n%s\nArguments: %o`, ex.stack || (`(${ex.name}) ${ex.message}`), args); return defaultValue; } }; return descriptor; }; }