@huz-com/error-core

Abstract error & error helper

Usage no npm install needed!

<script type="module">
  import huzComErrorCore from 'https://cdn.skypack.dev/@huz-com/error-core';
</script>

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" 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