# jsonql-errors

> Jsonql js error classes use across the projects

Latest version **1.2.1** (published 2020-03-15) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2020-03-15 |
| First published | 2019-05-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 39.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Joel Chu |
| Maintainers | joelchu |
| Keywords | jsonql, Error |

## Links

- npm: https://www.npmjs.com/package/jsonql-errors
- Repository: https://gitee.com:to1source/jsonql
- Homepage: http://jsonql.org
- npm.io page: https://npm.io/package/jsonql-errors

## Dependencies (1)

- [jsonql-constants](https://npm.io/package/jsonql-constants.md) ^2.0.2

## 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.2.1 (latest) — 2020-03-15
- 1.2.0 — 2020-03-15
- 1.1.10 — 2019-12-08
- 1.1.9 — 2019-12-08
- 1.1.8 — 2019-12-05
- 1.1.7 — 2019-12-01
- 1.1.6 — 2019-11-11
- 1.1.5 — 2019-11-04
- 1.1.4 — 2019-11-04
- 1.1.3 — 2019-09-07
- 1.1.2 — 2019-08-19
- 1.1.1 — 2019-08-15
- 1.1.0 — 2019-08-15
- 1.0.9 — 2019-06-11
- 1.0.8 — 2019-05-23
- … 10 more at https://npm.io/package/jsonql-errors/versions

## README

# jsonql-errors

This module exports a bunch of custom Error class for developer to use.
When the server side throw error, the client side will try to throw exactly
the same error and as developer you can clearly understand what is happening.

## Example

```js
// bunch of setup
client.query.getSomething(1)
  .then(result => /* do your thing */)
  .catch(err => {
    if (err instanceof JsonqlValidateError) {
      // update your UI to show the validation error

    } else if (err instanceof Jsonql500Error) {
      // ooops the server is down
    } else {
      // then this will NOT be an error throw from jsonql system
    }
  })
```

## List of Errors

### Server side errors

- Jsonql406Error
- Jsonql500Error
- JsonqlAuthorisationError
- JsonqlContractAuthError
- JsonqlResolverAppError
- JsonqlResolverNotFoundError

### Check Options errors

- JsonqlCheckerError
- JsonqlEnumError
- JsonqlTypeError

### Share errors

- JsonqlValidationError
- JsonqlError
- JsonqlServerError

## Functions

This package also export several useful help functions, and we use this
across multiple jsonql modules.

### getErrorByStatus

Get the error class name by it's status code, use on client side

arguments:
- statusCode {number} the status code
- contract {boolean} if this is from the contract *hack*

returns:
- {string} the name of the error class

### clientErrorsHandler

Check the resolver return result for error, use on client side

arguments:
- result {object} after we call a resolver and check the result if it's contain an error

returns:
- {object} if its passed then just return the result or throw a new error

### finalCatch

Repackage the error throw from the application

arguments:
- e {object} the error we catch

returns:
- throw the correct structure in our own error classes

### getErrorNameByInstance

Compare a list of errors class with the error we catch, then get it's name

arguments:
- errs {array} list of error classes
- e {object} the error object we captured

returns:
- {string} the name of the error class or `unknown` if it's not ours

## CONSTANTS

There are two constants export from this module as well

- `JSONQL_ERRORS_INFO` gives you the version number
- `UNKNOWN_ERROR` this is to use with the `getErrorNameByInstance` when we could not determine what type of error it is.

### general error

This is a standalone error type for use in a different type of module.
This is not export from the default export path, therefore you need to import it directly:

```js
import GeneralError from 'jsonql-errors/general'
```

---

ISC (c) 2019 NEWBRAN LTD / TO1SOURCE.CN

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