# that-koa-error

> A lightweight and extendable Error Handler library for Koa Applications

Latest version **1.0.11** (published 2019-06-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install that-koa-error
pnpm add that-koa-error
yarn add that-koa-error
bun add that-koa-error
```

## 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.0.11 |
| Published | 2019-06-25 |
| First published | 2018-10-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 20.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | thatdevsteve |

## Links

- npm: https://www.npmjs.com/package/that-koa-error
- Repository: https://github.com/ThatDevCompany/that-koa-error
- npm.io page: https://npm.io/package/that-koa-error

## Dependencies (1)

- [colors](https://npm.io/package/colors.md) ^1.3.2

## Recent versions

- 1.0.11 (latest) — 2019-06-25
- 1.0.10 — 2019-06-21
- 1.0.9 — 2019-04-12
- 1.0.8 — 2019-01-20
- 1.0.7 — 2019-01-20
- 1.0.6 — 2019-01-16
- 1.0.5 — 2018-12-17
- 1.0.4 — 2018-11-22
- 1.0.3 — 2018-11-21
- 1.0.2 — 2018-11-21
- 1.0.1 — 2018-11-21
- 0.0.30 — 2018-11-21
- 0.0.29 — 2018-11-07
- 0.0.28 — 2018-11-04
- 0.0.27 — 2018-11-01
- … 25 more at https://npm.io/package/that-koa-error/versions

## README

# That Koa Error
[![CircleCI](https://circleci.com/gh/ThatDevCompany/that-koa-error.svg?style=svg)](https://circleci.com/gh/ThatDevCompany/that-koa-error)

##  Overview
A lightweight and extendable Error Handler library for Koa Applications

When any part of the application throws an Errors the error middleware
will intercept it and gracefully respond to the user

Any Error which extends the ApplicationError class will be handled such
that responses are properly wrapped with status codes etc.

All non-application errors are treated as 500 Internal Server Errrors

All errors will be logged to the console

### Attaching Middleware
The below TYPESCRIPT provides an example of attaching the library to the
Koa Application

```
import * as Koa from 'koa'
import { error } from 'that-koa-error'

const app = new Koa()

app.use(error())
```

### Throwing Application Errors
The below TYPESCRIPT provides an example of how to throw an Application
Error.

Please note: the ApplicationError class itself is abstract - so we can
only throw an extension class. The basic extension is the GeneralError

```
some code...

if (something bad happened) {
    throw new GeneralError('A message to only display in console', arguments)
}

some more code...
```

#### assert Application Errors
A handy utility for quickly and cleanly throwing GeneralErrors via
assertion

```
function myFunction(a: string, b: string) {
    assert(a, 'A must be provided')
    assert(
        b.length === a.length,
        'B must be the same length as A',
        {a, b}  // Pass on useful debug info here
    )
}
```

#### expectAsyncToThrow
A handy utility for testing

```
it('should throw an error in an async function', async() {
    await expectAsyncToThrow(async () => {
        throw new Error('Something happened')
    })
})
// This will be PASS


it('should throw an error in an async function', async() {
    await expectAsyncToThrow(async () => {
        return Promise.resolve()
    })
})
// This will be FAIL
```

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