@huz-com/error-core
v1.0.17
Published
Abstract error & error helper
Downloads
11
Readme
Huz.Com > Component > Error Core
- Abstract error
- Error helper for error, and log
Standards
- Language:
TS
- Eslint:
Yes
- Static Code Analysis:
Yes
IntelliJ Code Inspections - DDD - Document Driven:
Yes
- EDD - Exception Driven:
Yes
- TDD - Test Driven:
Yes
go to test folder - Standards Complied: Huz Standards
Commands
npm run clear
// clears "dist" foldernpm run lint
// runs eslint for static code analysisnpm run test
// runs test files in "test" foldernpm run build
// builds JS files at "dist" foldernpm publish
ornpm run publix
// publishes "dist" folder to npm
Install
npm i @huz-com/error-core
Sample
const {AbstractError} = require('@huz-com/error-core');
export class GameNotFoundError extends AbstractError {
status = 404;
constructor(id: string|number) {
// signature: (message: string, parameters?: Record<string, unknown>)
super(`Game record could not be found with id: ${id}`, {id});
}
}
// when error raised
throw new GameNotFoundError(345321);
// when using error object
const err = new GameNotFoundError('abc01');
console.log(err);
// It prints
/*
{
// inherited from Error
name: 'GameNotFoundError',
// inherited from Error
message: 'Game record could not be found with id: abc01',
// inherited from AbstractError
parameters: {
id: 'abc01'
},
// GameNotFoundError custom property
status: 404
}
*/
console.log(err instanceof Error); // true, because inherited from JS core Error
console.log(err instanceof AbstractError); // true, because inherited from AbstractError
console.log(err instanceof GameNotFoundError); // true