Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@beforeyoubid/error-adapter

Package Overview
Dependencies
Maintainers
8
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@beforeyoubid/error-adapter

A module to standardize error handling across the BYB platform

  • 1.0.11
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
268
increased by15.52%
Maintainers
8
Weekly downloads
 
Created
Source

BYB Error Adapter

This is an error handling module that supports multiple error types and the handling of each type accordingly using Sentry.

The following npm packages have been extended in this module:

This module supports using environment variables to filter local error alerts, as well as disabling error alerts entirely. This is especially useful for microservice architectures where errors may be handled elsewhere.

Supported Error types

Error TypeAlert Raised in Sentry
Server ErrorYes
Not AuthorizedYes
Not AuthenticatedNo
Not FoundNo
Validation ErrorNo
Validation ErrorNo
User Input ErrorNo
Conflict ErrorNo

This module is designed to work on a native node runtime and in a Lambda environment. For Lambda, please see the withSentry section below.

Setup

Installation

  yarn add @beforeyoubid/error-adapter

Environment Variables

Capturing can be controlled through the following environment variables. You can set them manually in your serverless.yml (Serverless Framework) or template.yml (AWS SAM) or let them be configured automatically using the Serverless Sentry Plugin during deployment.

Environment VariableDescription
SENTRY_DSNSentry DSN Url
SENTRY_ENVIRONMENTEnvironment (optional, e.g. "dev" or "prod")
SENTRY_RELEASERelease number or version of your project (optional)
SENTRY_AUTO_BREADCRUMBSAutomatically create breadcrumbs (see Sentry SDK docs, default to true)
SENTRY_FILTER_LOCALDon't report errors from local environments (defaults to true)
SENTRY_CAPTURE_ERRORSEnable capturing Lambda errors (defaults to true)
SENTRY_CAPTURE_UNHANDLEDEnable capturing unhandled Promise rejections (defaults to true)
SENTRY_CAPTURE_UNCAUGHTEnable capturing uncaught exceptions (defaults to true)
SENTRY_CAPTURE_MEMORYEnable monitoring memory usage (defaults to true)
SENTRY_CAPTURE_TIMEOUTSEnable monitoring execution timeouts (defaults to true)
SENTRY_SOURCEMAPSEnable Webpack sourcemaps support (defaults to false)
DISABLE_SENTRYDisable Sentry, not set automatically (defaults to false)

Use Together With the Serverless Sentry Plugin

The Serverless Sentry Plugin allows simpler configuration of the library through the serverless.yml and will upload your source-maps automatically during deployment. This is the recommended way of using the serverless-sentry-lib library.

Instead of manually setting environment variables, the plugin determines and sets them automatically. In the serverless.yml simply load the plugin and set the dsn configuration option as follows:

service: my-serverless-project
provider:
  # ...
plugins: serverless-sentry
custom:
  sentry:
    dsn: https://xxxx:yyyy@sentry.io/zzzz # URL provided by Sentry
    filterLocal: true # Optional

You can still manually set environment variables on a per-function level to overwrite the default ones. Please refer to the Serverless Sentry Plugin for full documentation of all available options.

Usages

The modules caters for two usage mechanisms:

  1. Using withSentry higher-order function by wrapping handler functions in withSenty function.
  2. Using the Sentry Client to capture messages and exceptions

1) Using withSentry higher-order function

Original Lambda Handler Code:

  export async function handler(event, context) {
    console.log("EVENT: \n" + JSON.stringify(event, null, 2));
    return context.logStreamName;
  }

New Lambda Handler Code Using withSentry For Sentry Reporting

  import { withSentry } from "@beforeyoubid/error-adapter"; // This helper library

  export const handler = withSentry(async (event, context) => {
    console.log("EVENT: \n" + JSON.stringify(event, null, 2));
    return context.logStreamName;
  });

Custom configuration options may also be used. Please refer to the Serverless Sentry Plugin for full documentation of all available options.

2) Using the Sentry Client to Capture Messages and Exceptions

  import { Sentry } from "@beforeyoubid/error-adapter"; // This helper library
  Sentry.initialise(); // This sets up the Sentry client based on environment variables

  export const cronHandler = async (event, context) => {
    try {
      console.log("EVENT: \n" + JSON.stringify(event, null, 2));
      return context.logStreamName;
    } catch (error) {
      Sentry.captureException(error);
    }
  };

Roadmap

  • Extend this module to support centralised copy on error messages (useful for business users seeing the error, as well as developers investigating the error).

FAQs

Package last updated on 20 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc