Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11x 11x 11x 11x 1x 1x 11x 1x 1x 1x 1x 1x 1x 11x 4x 4x 4x 4x 56x 56x 21x 56x 275x 1x | import type {IErrorFactory, ILog, IMeta, ITypedError} from '@feasibleone/blong/types';
import {Internal} from '@feasibleone/blong/types';
import Errors from './error.ts';
interface IConfig {
logLevel: Parameters<ILog['logger']>[0];
errorPrint: string;
}
export default class ErrorFactory extends Internal implements IErrorFactory {
#error: ReturnType<typeof Errors>;
#config: IConfig = {
logLevel: 'debug',
errorPrint: '',
};
public constructor(config: IConfig, {log}: {log: ILog}) {
super({log});
this.merge(this.#config, config);
this.#error = Errors({
logFactory: {
createLog: (...params: Parameters<ILog['logger']>) => log?.logger(...params) || {},
} as unknown as Parameters<typeof Errors>[0]['logFactory'],
logLevel: this.#config.logLevel,
errorPrint: this.#config.errorPrint,
});
}
public register<T>(
errors: T,
): Record<keyof T, (params?: unknown, $meta?: IMeta) => ITypedError> {
return this.#error.register(errors);
}
public get(name: string) {
return this.#error.get(name);
}
public fetch(type: string): object {
return this.#error.fetch(type);
}
public define(
id: string,
superType: string | {type: string},
message: string,
): (params?: unknown, $meta?: IMeta) => ITypedError {
return this.#error.define(id, superType, message);
}
}
|