twing
Version:
First-class Twig engine for Node.js
31 lines (30 loc) • 1.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTraceableMethod = getTraceableMethod;
exports.getSynchronousTraceableMethod = getSynchronousTraceableMethod;
const runtime_1 = require("../error/runtime");
const error_1 = require("../error");
function getTraceableMethod(method, location, templateSource) {
return ((...args) => {
return method(...args)
.catch((error) => {
if (!(0, error_1.isATwingError)(error)) {
throw (0, runtime_1.createRuntimeError)(error.message, location, templateSource, error);
}
throw error;
});
});
}
function getSynchronousTraceableMethod(method, location, templateSource) {
return ((...args) => {
try {
return method(...args);
}
catch (error) {
if (!(0, error_1.isATwingError)(error)) {
throw (0, runtime_1.createRuntimeError)(error.message, location, templateSource, error);
}
throw error;
}
});
}