UNPKG

@httpc/kit

Version:

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

20 lines (19 loc) 684 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Catch = void 0; 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; }; } exports.Catch = Catch;