# @salesduck/errors

> Extended errors

Latest version **1.1.0** (published 2023-07-12) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2023-07-12 |
| First published | 2023-07-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | dyrkow |
| Maintainers | webworkdeveloper |

## Links

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

## Recent versions

- 1.1.0 (latest) — 2023-07-12

## README

# @salesduck/errors

Extended errors for your app

## Setup

Add to your project

```
yarn add @salesduck/errors
```

## Usage

Just import and create instance

```ts
import { ApplicationError } from '@salesduck/errors';

throw new ApplicationError();
```

Or with parameters

```ts
throw new ApplicationError({
    message: "User with email exists",
    code: 'USER_WITH_EMAIL_EXISTS',
    email: 'some@gmail.com' // Meta information, will be passed to stack trace
});
```

## Safety

Secure shipment to the customer

```ts
res.json(new ApplicationError({ message: 'Some error', code: 'USER_NOT_FOUND' }));
```

user will see this response

```json
{
    "message": "Some error",
    "code": "USER_NOT_FOUND"
}
```

## Logging

The error is easy to log

```ts
const error = new ApplicationError({
    cause: new ApplicationError({
        id: 'users'
    })
});

logger.error(error.toString());
```
In logs you see

```
 ApplicationError: Application Error
          at Object.<anonymous> (.../ApplicationError/spec.ts:35:30)
          at Object.asyncJestTest (.../node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:106:37)
          at .../node_modules/jest-jasmine2/build/queueRunner.js:45:12
          at new Promise (<anonymous>)
          at mapper (.../node_modules/jest-jasmine2/build/queueRunner.js:28:19)
          at .../node_modules/jest-jasmine2/build/queueRunner.js:75:41
          code UNKNOWN
      caused by ApplicationError: Application Error
          at Object.<anonymous> (.../ApplicationError/spec.ts:36:24)
          at Object.asyncJestTest (.../node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:106:37)
          at .../node_modules/jest-jasmine2/build/queueRunner.js:45:12
          at new Promise (<anonymous>)
          at mapper (.../node_modules/jest-jasmine2/build/queueRunner.js:28:19)
          at .../node_modules/jest-jasmine2/build/queueRunner.js:75:41
          by id "users"
          code UNKNOWN
```

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