@onedaycat/ts-error

A library to create application error

Usage no npm install needed!

<script type="module">
  import onedaycatTsError from 'https://cdn.skypack.dev/@onedaycat/ts-error';
</script>

README

npm (scoped) GitHub Coverage Status Build Status

ts-error

A library to create application error, there are 8 definition type that including

  • BAD_REQUEST
  • NOT_FOUND
  • TIMEOUT
  • FORBIDDEN
  • UNAUTHORIZED
  • MAINTENANCE
  • VALIDATION_ERROR
  • INTERNAL_ERROR

Install

npm install @onedaycat/ts-error

Usage

import { def } from '@onedaycat/ts-error';

// define application error
const error = {
  userNotFound: def.notFound('user_not_found', 'user not found');
  productNotFound: def.notFound('product_not_found', 'product not found');
}

try {
  // do stuff
} catch (e) {
  // throw application error that defined instead
  throw error.userNotFound.new().withCause(e);
}

Contributing

  1. Fork this repository.
  2. Create new branch with feature name in format feature/FEATURE_NAME
  3. Run npm install or yarn
  4. Create your feature.
  5. Commit and set commit message with feature name.
  6. Push your code to your fork repository.
  7. Create pull request.