will-core
Version:
core module
36 lines (35 loc) • 1.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SystemHandler = void 0;
const will_api_1 = require("will-api");
const BaseHandler_1 = require("./BaseHandler");
const LoggingHandler_1 = require("./LoggingHandler");
const EnvironmentVariable_1 = require("../utils/EnvironmentVariable");
const VerifyError_1 = require("../models/VerifyError");
class SystemHandler extends BaseHandler_1.BaseHandler {
async exposeOperation(context, model, operation) {
await this.exposeContext(context);
}
async callFunctional(context, info, functional) {
if (this.model && this.isValidModelConfig("privateAlias", this.model)) {
await this.exposeFunctional(context, this.model, { operate: info.operate });
if (info.raw) {
context.meta.$responseRaw = true;
context.meta.$responseType = "text/html";
}
return functional.call(this, context, this.model);
}
return Promise.reject(new VerifyError_1.VerifyError("Invalid setting", will_api_1.HTTP.NOT_ACCEPTABLE, -16006));
}
track(context, info) {
if (EnvironmentVariable_1.ALWAYS_DB_TRACKING) {
if (!info.tracker)
info.tracker = context.meta.pid;
let logging = new LoggingHandler_1.LoggingHandler();
logging.trackInfo = info;
logging.insert(context).catch(ex => this.logger.error(this.constructor.name, ex));
}
return Promise.resolve();
}
}
exports.SystemHandler = SystemHandler;