micro-raven-errors - Micro wrapper for capturing application errors with Raven
Installation
yarn add @ansaro-ai/micro-raven-errors
Usage
micro-raven-errors exports a single function that wraps a micro services, and captures any errors with an http status of 500 or greater with Raven.
MicroRavenErrors: (fn: MicroFunction, dsn: string) => MicroFunction
type MicroFunction = (req http.IncomingMessage, reshttp.ServerResponse) => any
fn
: A function that could otherwise run standalone inside micro. This is your application code.
dsn
: The Data Source Name is a URL where Sentry listens to collect errors from your application.
const micro = require("micro")
const MicroRavenErrors = require("@ansaro-ai/micro-raven-errors");
const testServer = async (req, res) => {
const body = await micro.json(req);
if (!body.name) {
throw micro.createError(400);
}
if (body.massiveError) {
throw micro.createError(500, "This is a massive error");
}
return { success: true };
};
module.exports = MicroRavenErrors(testServer, "YOUR_RAVEN_DSN")