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


2.0.24 years ago4 years agoMinified + gzip package size for @ansaro/micro-raven-errors in KB



Micro wrapper for capturing application errors with Sentry (aka raven)


yarn add @ansaro/micro-raven-errors


micro-raven-errors exports a single function that wraps a micro function and captures any errors with a status code of 500 or greater with Raven.

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 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, 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.

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);

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.