registry logger

This commit is contained in:
Erik 2022-11-20 18:38:29 +02:00
parent 975dd6bceb
commit 05c956ca71
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -11,6 +11,7 @@ class Registry {
this.endpoints = new Collection();
this.path = options.path;
this.server = server;
this.logger = server.createLogger(this);
}
get print () {
@ -29,7 +30,7 @@ class Registry {
async loadEndpoints () {
const { server, endpoints } = this;
const { server, endpoints, logger } = this;
return (async function read (pth) {
@ -44,11 +45,16 @@ class Registry {
const Endpoint = require(file);
if (!Endpoint) continue;
if (typeof Endpoint !== 'function') {
logger.warn(`Attempted to instantiate invalid class at ${file.name}`);
continue;
}
const endpoint = new Endpoint(server);
endpoint.init();
if (endpoints.has(endpoint.resolveable)) throw new Error(`Error registering endpoint ${endpoint.resolveable}: an endpoint with that resolveable already exists`);
endpoints.set(endpoint.resolveable, endpoint);
logger.info(`Created endpoint ${endpoint.name}`);
}