@huz-com/error-core
TypeScript icon, indicating that this package has built-in type declarations

1.0.17 • Public • Published

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" folder
  • npm run lint // runs eslint for static code analysis
  • npm run test // runs test files in "test" folder
  • npm run build // builds JS files at "dist" folder
  • npm publish or npm 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

Readme

Keywords

Package Sidebar

Install

npm i @huz-com/error-core

Weekly Downloads

11

Version

1.0.17

License

ISC

Unpacked Size

28.6 kB

Total Files

14

Last publish

Collaborators

  • demiremrece