diff --git a/package-lock.json b/package-lock.json index 323088f..5ede068 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@shaddyhm/configs", - "version": "0.2.0", + "version": "0.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@shaddyhm/configs", - "version": "0.2.0", + "version": "0.2.1", "license": "MIT", "dependencies": { "app-root-path": "^3.1.0", diff --git a/package.json b/package.json index 0f68efb..53172c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@shaddyhm/configs", - "version": "0.2.0", + "version": "0.2.1", "description": "A simple application configuration library", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/errors/extension.error.ts b/src/errors/extension.error.ts new file mode 100644 index 0000000..266d6b1 --- /dev/null +++ b/src/errors/extension.error.ts @@ -0,0 +1,7 @@ +import { PackageError } from './package.error'; + +export class ExtensionError extends PackageError { + constructor(message: string) { + super(message); + } +} diff --git a/src/errors/parser.error.ts b/src/errors/files.error.ts similarity index 69% rename from src/errors/parser.error.ts rename to src/errors/files.error.ts index 189ca9b..f372f2b 100644 --- a/src/errors/parser.error.ts +++ b/src/errors/files.error.ts @@ -1,6 +1,6 @@ import { PackageError } from './package.error'; -export class ParserError extends PackageError { +export class FilesError extends PackageError { constructor(message: string) { super(message); } diff --git a/src/errors/index.ts b/src/errors/index.ts index e694af6..7ede200 100644 --- a/src/errors/index.ts +++ b/src/errors/index.ts @@ -1,4 +1,5 @@ export { DirectoryError } from './directory.error'; +export { ExtensionError } from './extension.error'; export { FileError } from './file.error'; -export { ParserError } from './parser.error'; +export { FilesError } from './files.error'; export { ResolverError } from './resolver.error'; diff --git a/src/index.ts b/src/index.ts index aa7e1e9..643e343 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,10 +5,9 @@ import * as path from 'path'; import * as util from 'util'; import * as YAML from 'yaml'; -import { ResolverError } from './errors'; +import { ExtensionError, FilesError, ResolverError } from './errors'; import { DirectoryError } from './errors/directory.error'; import { FileError } from './errors/file.error'; -import { ParserError } from './errors/parser.error'; const readFileAsync = util.promisify(fs.readFile); @@ -73,7 +72,7 @@ export class Configs implements IConfigs { ); if (!resolver.files || !resolver.files.length) - throw new FileError(`No config files provided for ${resolver.env} env`); + throw new FilesError(`No config files provided for ${resolver.env} env`); // validate resolver files and extensions resolver.files.forEach((file) => { @@ -88,7 +87,7 @@ export class Configs implements IConfigs { const ext = path.extname(file); const isExtensionSupported = ['.yaml', '.yml'].includes(ext); if (!isExtensionSupported) - throw new ParserError( + throw new ExtensionError( `Unsupported file extension ${ext}. Only .yaml and .yml are supported.`, ); }); diff --git a/tests/index.spec.ts b/tests/index.spec.ts index d15b6fe..c136401 100644 --- a/tests/index.spec.ts +++ b/tests/index.spec.ts @@ -3,8 +3,9 @@ import * as assert from 'assert'; import { Configs } from '../src/'; import { DirectoryError, + ExtensionError, FileError, - ParserError, + FilesError, ResolverError, } from '../src/errors'; @@ -47,7 +48,7 @@ describe('Test unhappy paths', () => { }, ]; }); - }, new FileError('No config files provided for development env')); + }, new FilesError('No config files provided for development env')); }); it('should throw if no resolver is found', () => { @@ -95,7 +96,7 @@ describe('Test unhappy paths', () => { }, ]; }); - }, new ParserError('Unsupported file extension .json. Only .yaml and .yml are supported.')); + }, new ExtensionError('Unsupported file extension .json. Only .yaml and .yml are supported.')); }); });