# @nayotta/errors

> js common business errors

Latest version **0.3.0** (published 2025-12-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @nayotta/errors
pnpm add @nayotta/errors
yarn add @nayotta/errors
bun add @nayotta/errors
```

## Health

**Score 60/100 (C)** — status: stable.

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

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2025-12-01 |
| First published | 2023-06-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 38 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | nayotta.fe |
| Maintainers | goku-gaga, classlfz |
| Keywords | errors |

## Links

- npm: https://www.npmjs.com/package/@nayotta/errors
- Repository: https://github.com/nayotta/js-errors
- Homepage: https://github.com/nayotta/js-errors#readme
- Issues: https://github.com/nayotta/js-errors/issues
- npm.io page: https://npm.io/package/@nayotta/errors

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

- 0.3.0 (latest) — 2025-12-01
- 0.2.0 — 2023-07-12
- 0.1.0 — 2023-06-30
- 0.1.0-beta.3 — 2023-06-30
- 0.1.0-beta.2 — 2023-06-30
- 0.1.0-beta.1 — 2023-06-30

## README

# @nayotta/errors

[![Lint and Build](https://github.com/nayotta/js-errors/actions/workflows/lint-build.yml/badge.svg)](https://github.com/nayotta/js-errors/actions/workflows/lint-build.yml)[![Node.js Package](https://github.com/nayotta/js-errors/actions/workflows/release.yml/badge.svg)](https://github.com/nayotta/js-errors/actions/workflows/release.yml)

> common business errors

## install

```shell
$ npm install @nayotta/errors --save
```

## use

```js
// COMMONJS
const {
	ToBeDoneError,
	errors,
	JsError
} = require('@nayotta/errors')
// ESM
import {
	ToBeDoneError,
	errors,
	JsError
} from '@nayotta/errors'

async function do () {
	throw new errors.ToBeDoneError('function do')
}

async function run () {
	const res = await do().catch(err => err)
	if (res instanceof Error) {
		if (errors.isToBeDoneError(res)) {
			console.log(res.name) // TBD_ERROR
			console.log(res.message) // TBD: function a
			console.log(res.code) // 403
			console.log(res)
			return
		}
		throw res
	}
}

// custom errors
const TEST_ERROR_NAME = 'TEST_ERROR'
class TestError extends Error {
	public readonly name: string = TEST_ERROR_NAME
	public readonly code: number = 400
	public message: string = 'test'
	constructor (message?: string) {
		super()
		this.message += `: ${message}`
	}
}

function isTestError (err: Error) {
	return errors.isError(err, { name: TEST_ERROR_NAME })
}

async function doSomethingCustom () {
	throw new TestError('do something custom')
}

async function runCustomErr () {
	const res = await doSomethingCustom().catch(err => err)
	if (res instanceof Error) {
		if (isTestError(res)) {
			console.log(res.name) // TEST_ERROR
			console.log(res.message) // echo: do something custom
			console.log(res.code) // 400
			console.log(res)
			return
		}
		throw res
	}
}
```

### errors

#### UnauthorizationError

- name: `UNAUTHORIZATION_ERROR`
- code: `401`
- message: `unauthorization: <message>`

#### NotFoundError

- name: `NOT_FOUND_ERROR`
- code: `404`
- message: `not found: <name>`

#### ResourceNotFoundError

- name: `RESOURCE_NOT_FOUND_ERROR`
- code: `404`
- message: `resource not found: <resource>:<name> not found`

#### ResourceAlreadyExistedError

- name: `RESOURCE_ALREADY_EXISTED_ERROR`
- code: `400`
- message: `resource already existed: <resource>:<name> already existed`

#### InvalidDataError

- name: `INVALID_DATA_ERROR`
- code: `400`
- message: `invalid data: <name>`

#### RequiredError

- name: `REQUIRED_ERROR`
- code: `400`
- message: `required: <name>`

#### ArgumentRequiredError

- name: `ARGUMENT_REQUIRED_ERROR`
- code: `400`
- message: `argument required: <name>`

#### OptionRequiredError

- name: `OPTION_REQUIRED_ERROR`
- code: `400`
- message: `option required: <name>`

#### HeaderRequiredError

- name: `HEADER_REQUIRED_ERROR`
- code: `400`
- message: `header required: <name>`

#### NotImplementedError

- name: `NOT_IMPLEMENTED_ERROR`
- code: `403`
- message: `not implemented: <name>`

#### UnsupportedError

- name: `UNSUPPORTED_ERROR`
- code: `403`
- message: `unsupported: <name>`

#### TypeSupportedError

- name: `TYPE_SUPPORTED_ERROR`
- code: `403`
- message: `type supported: <type>:<name>`

#### NotAllowedError

- name: `NOT_ALLOWED_ERROR`
- code: `403`
- message: `not allowed: <name>`

#### TypeNotAllowedError

- name: `TYPE_NOT_ALLOWED_ERROR`
- code: `403`
- message: `type not allowed: <type>:<name>`

#### UnexpectedError

- name: `UNEXPECTED_ERROR`
- code: `500`
- message: `unexpected: <name>`

#### ToBeDoneError

- name: `TBD_ERROR`
- code: `403`
- message: `TBD: <name>`

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