/**
* @NApiVersion 2.1
* Custom Error Handler Base Class
*/
define(['N/log', 'N/runtime'], (log, runtime) => {
class ErrorHandler {
constructor() {
this.scriptId = runtime.getCurrentScript().id;
}
wrapExecution(functionName, fn, context = {}) {
try {
log.debug({
title: `${functionName} - Start`,
details: context
});
const result = fn();
log.audit({
title: `${functionName} - Complete`,
details: { success: true }
});
return result;
} catch (error) {
log.error({
title: `${functionName} - Error`,
details: { error: error.message, stack: error.stack, context }
});
throw error;
}
}
loadModule(moduleName) {
return require(moduleName);
}
}
return ErrorHandler;
});