An open API service indexing awesome lists of open source software.

https://github.com/nswbmw/hono-throw

A Hono middleware making it easy to throw HTTPException.
https://github.com/nswbmw/hono-throw

Last synced: about 1 month ago
JSON representation

A Hono middleware making it easy to throw HTTPException.

Awesome Lists containing this project

README

          

## hono-throw

A Hono middleware making it easy to throw HTTPException.

### Install

```sh
$ npm i hono-throw --save
```

### Example

```js
import { Hono } from 'hono'
import { honoThrow } from 'hono-throw'
import { serve } from '@hono/node-server'

const app = new Hono()
honoThrow(app) // or app.use(honoThrow())

app.get('/', (c) => {
c.throw(400, 'error!!!')

// Equivalent to:
// c.throw(400, { message: 'error!!!' })

// Equivalent to:
// throw new HTTPException(400, { message: 'error!!!' })
})

serve(app)
```

### Test(100% coverage rate)

```sh
$ npm test
```

### License

MIT