UNPKG

@adapty/capacitor

Version:
33 lines 1.05 kB
function toJSON() { return { message: this.message, name: this.name, stack: this.stack, originalError: this.originalError instanceof Error ? { message: this.originalError.message, name: this.originalError.name, } : this.originalError, }; } /** * Wraps a user-provided callback with error context enrichment. * Catches exceptions and wraps them with source and handler information. */ export function withErrorContext(callback, handlerName, source) { const wrapped = function (...args) { try { return callback.apply(this, args); } catch (error) { const message = `Unhandled exception in user's handler in ${source}.${handlerName}`; const wrappedError = new Error(message); wrappedError.originalError = error; wrappedError.toJSON = toJSON; throw wrappedError; } }; return wrapped; } //# sourceMappingURL=with-error-context.js.map