# @ansaro/micro-raven-errors

> A tiny module for sending Raven errors using Zeit's micro server framework

Latest version **2.0.2** (published 2018-07-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install @ansaro/micro-raven-errors
pnpm add @ansaro/micro-raven-errors
yarn add @ansaro/micro-raven-errors
bun add @ansaro/micro-raven-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 | 2.0.2 |
| Published | 2018-07-25 |
| First published | 2018-06-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 5.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ben Goldberg |
| Maintainers | bgoldberg15, maxbeatty |

## Links

- npm: https://www.npmjs.com/package/@ansaro/micro-raven-errors
- npm.io page: https://npm.io/package/@ansaro/micro-raven-errors

## Dependencies (2)

- [micro](https://npm.io/package/micro.md) ^9.3.2
- [@ansaro/errors](https://npm.io/package/@ansaro/errors.md) ^0.2.2

## Recent versions

- 2.0.2 (latest) — 2018-07-25
- 2.0.1 — 2018-07-14
- 2.0.0 — 2018-07-13
- 1.1.0 — 2018-06-25
- 1.0.1 — 2018-06-01
- 1.0.0 — 2018-06-01

## README

# micro-raven-errors

[Micro](https://github.com/zeit/micro) wrapper for capturing application errors with [Sentry](https://sentry.io) (aka raven)

## Installation

```
yarn add @ansaro/micro-raven-errors
```

## Usage

_micro-raven-errors_ exports a single function that wraps a [micro](https://github.com/zeit/micro) function and captures any errors with a status code of 500 or greater with [Raven](https://docs.sentry.io/clients/node/).

```
import typeof RavenOptions from "@ansaro/errors"

type MicroFunction = (req http$IncomingMessage, res http$ServerResponse) => any

reportErrors: (opts: RavenOptions, fn: MicroFunction) => MicroFunction
```

- `opts`: an object of [optional settings](https://docs.sentry.io/clients/node/config/#optional-settings) to send when capturing exceptions
- `fn`: a function that could otherwise run standalone inside micro. This is your application code.

_micro-raven-errors_ also expect you to provide a [Data Source Name](https://docs.sentry.io/quickstart/#configure-the-dsn), which is a URL where Sentry listens to collect errors from your application. You'll need to set `process.env.SENTRY_DSN` to be this URL.

Unexpected application errors and HTTP errors with a status code of 500 or higher will be reported to Sentry. Expected HTTP errors like 404s will not be reported.

```js
const micro = require("micro");
const reportErrors = require("@ansaro/micro-raven-errors");

const testServer = async (req, res) => {
  const body = await micro.json(req);

  if (!body.name) {
    throw micro.createError(400); // not reported to Sentry
  }

  if (body.massiveError) {
    throw micro.createError(500, "This is a massive error"); // reported to Sentry
  }

  return { success: true };
};

module.exports = reportErrors({}, testServer);
```

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