diff --git a/packages/http/build/utils.mjs b/packages/http/build/utils.mjs index be42996..5149218 100644 --- a/packages/http/build/utils.mjs +++ b/packages/http/build/utils.mjs @@ -20,6 +20,7 @@ export async function saveFile(content, filePath) { /** * Load template (.tpl) file from disk. * @param file + * @return Promise */ export async function loadTemplate(file) { const tplPath = path.isAbsolute(file) ? diff --git a/packages/http/src/errors/base/client.ts b/packages/http/src/errors/base/client.ts index 89f611f..148a72d 100644 --- a/packages/http/src/errors/base/client.ts +++ b/packages/http/src/errors/base/client.ts @@ -1,7 +1,10 @@ +import type { Input } from '../../types'; import { HTTPError, isHTTPError } from './http'; export class ClientError extends HTTPError { - + constructor(...input: Input[]) { + super({ expose: true }, ...input); + } } export function isClientError(input: unknown): input is ClientError { diff --git a/packages/http/src/errors/base/server.ts b/packages/http/src/errors/base/server.ts index 27c8263..08b2768 100644 --- a/packages/http/src/errors/base/server.ts +++ b/packages/http/src/errors/base/server.ts @@ -1,7 +1,10 @@ +import type { Input } from '../../types'; import { HTTPError, isHTTPError } from './http'; export class ServerError extends HTTPError { - + constructor(...input: Input[]) { + super({ expose: false }, ...input); + } } export function isServerError(error: unknown): error is ServerError { diff --git a/packages/http/test/unit/module.spec.ts b/packages/http/test/unit/module.spec.ts index 595875b..f849353 100644 --- a/packages/http/test/unit/module.spec.ts +++ b/packages/http/test/unit/module.spec.ts @@ -1,6 +1,6 @@ // eslint-disable-next-line max-classes-per-file import { - HTTPError, InternalServerError, NotFoundError, isClientError, isHTTPError, isServerError, + ClientError, HTTPError, InternalServerError, NotFoundError, ServerError, isClientError, isHTTPError, isServerError, } from '../../src'; describe('src/module.ts', () => { @@ -25,6 +25,11 @@ describe('src/module.ts', () => { expect(error.statusCode).toEqual(500); }); + it('should create client error with default props', () => { + const error = new ClientError(); + expect(error.expose).toBeTruthy(); + }); + it('should recognize client error', () => { const error = new NotFoundError(); expect(isClientError(error)).toBeTruthy(); @@ -32,6 +37,11 @@ describe('src/module.ts', () => { expect(isHTTPError(error)).toBeTruthy(); }); + it('should create server error with default props', () => { + const error = new ServerError(); + expect(error.expose).toBeFalsy(); + }); + it('should recognize server error', () => { const error = new InternalServerError(); expect(isClientError(error)).toBeFalsy();