# commonjs-errors

> NodeJS dataverse base errors

Latest version **1.0.1** (published 2024-02-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install commonjs-errors
pnpm add commonjs-errors
yarn add commonjs-errors
bun add commonjs-errors
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2024-02-21 |
| First published | 2024-02-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 73.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Byteverse |
| Maintainers | anokhi0895 |
| Keywords | errors, http-status, express |

## Links

- npm: https://www.npmjs.com/package/commonjs-errors
- Repository: https://github.com/anokhimg/common-nodejs-components
- Homepage: https://github.com/anokhimg/common-nodejs-components/packages/errors
- Issues: https://github.com/anokhimg/common-nodejs-components/issues
- npm.io page: https://npm.io/package/commonjs-errors

## Dependencies (1)

- [http-status](https://npm.io/package/http-status.md) ^1.5.0

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2024-02-21
- 1.0.0 — 2024-02-21

## README

# `commonjs-errors`

Common errors used in the system

## Usage

## Creating custom errors

Create a class which should extend either APIError or Extendable error

```
export class TimeoutError extends ApiError {
  constructor(error?: Error) {
    super(
      "Request timeout error",
      {
        status: httpStatus.REQUEST_TIMEOUT,
        code: 'error.request-timeout',
/** if isPublic is set to true refers the error is known error and server should print the error message
if it's set to false, its unknown / unexpected error
*/
        isPublic: true,
      },
      error,
    );
  }
}

/** Use the created error class to throw error */
throw new TimeoutError(err);
```

## Using existing errors from the package
```
import { UnauthorizedError, ResourceNotFoundError } from 'commonjs-errors';

/** UnauthorizedError */
if (err instanceof UnauthorizedError) {
  throw new UnauthorizedError(err.message, err));
}

/** ResourceNotFoundError */
if(!resource){
 throw new ResourceNotFoundError(workspaceId.toString());
}

```

---
_Source: https://npm.io/package/commonjs-errors · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
