2.0.0 • Published 3 years ago

@mertsolak/custom-error v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Custom Error

Developed to select pre-defined error properties easily.

npm license size issue

Installation

Use node package manager to install @mertsolak/custom-error.

npm i @mertsolak/custom-error

Usage

Create an instance in any file.

// custom-error.ts

enum ErrorTypes {
  INTERNAL_SERVER_ERROR,
  BAD_REQUEST,
}

const properties = [
  {
    errorCode: ErrorTypes.INTERNAL_SERVER_ERROR,
    status: 500,
    message: 'Internal Server Error',
  },
  {
    errorCode: ErrorTypes.BAD_REQUEST,
    status: 400,
    message: 'The field ${ arg.fieldName } has to be type of ${ arg.fieldType }',
  },
];

export const customError = new CustomError(ErrorTypes, properties);

Import and use custom-error in everywhere.

// any-file.ts

import { customError } from './custom-error';

throw customError.select('BAD_REQUEST', { fieldName: 'email', fieldType: 'string' });
// OR
throw customError.select('INTERNAL_SERVER_ERROR');
// OR pre-defined error properties can be overwritten
throw customError.select('INTERNAL_SERVER_ERROR').setName('updatedName').setStatus(404);
2.0.0

3 years ago

1.0.0

3 years ago