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

https://github.com/so1ve/oak-json-error

Oak middleware JSON error
https://github.com/so1ve/oak-json-error

deno javascript typescript

Last synced: about 1 month ago
JSON representation

Oak middleware JSON error

Awesome Lists containing this project

README

          

# oak_json_error

The oak version of [koa-json-error](https://github.com/koajs/json-error).

## Usage

```ts
import { jsonErrorMiddleware } from "https://deno.land/x/oak_json_error/mod.ts";

const errorHandler = jsonErrorMiddleware();
app.use(errorHandler);
// ... Your code here ...
// app.use(route.routes())
```

## Customize

### Options

`format`: `(err: T) => any;`

```ts
const errorHandler = jsonErrorMiddleware({ // If the error is thrown by ctx.throw, it will have status
format: (err: Error & { status: number }) => {
return {
code: err.status,
message: err.message,
error: err.message,
};
},
});
```