
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
@beforeyoubid/error-adapter
Advanced tools
A module to standardize error handling across the BYB platform
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:
@sentry/node
library, which does not support the filtration of local errors by default, and the use of an environment variable to disable Sentry alerts.serverless-sentry-lib
library, which does not support the use of an environment flag to disable Sentry alerts.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.
Error Type | Alert Raised in Sentry |
---|---|
Server Error | Yes |
Not Authorized | Yes |
Not Authenticated | No |
Not Found | No |
Validation Error | No |
Payment Error | No |
User Input Error | No |
Conflict Error | No |
This module is designed to work on a native node runtime and in a Lambda environment. For Lambda, please see the withSentry section below.
yarn add @beforeyoubid/error-adapter
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 Variable | Description |
---|---|
SENTRY_DSN | Sentry DSN Url |
SENTRY_ENVIRONMENT | Environment (optional, e.g. "dev " or "prod ") |
SENTRY_RELEASE | Release number or version of your project (optional) |
SENTRY_AUTO_BREADCRUMBS | Automatically create breadcrumbs (see Sentry SDK docs, default to true ) |
SENTRY_FILTER_LOCAL | Don't report errors from local environments (defaults to true ) |
SENTRY_CAPTURE_ERRORS | Enable capturing Lambda errors (defaults to true ) |
SENTRY_CAPTURE_UNHANDLED | Enable capturing unhandled Promise rejections (defaults to true ) |
SENTRY_CAPTURE_UNCAUGHT | Enable capturing uncaught exceptions (defaults to true ) |
SENTRY_CAPTURE_MEMORY | Enable monitoring memory usage (defaults to true ) |
SENTRY_CAPTURE_TIMEOUTS | Enable monitoring execution timeouts (defaults to true ) |
SENTRY_SOURCEMAPS | Enable Webpack sourcemaps support (defaults to false ) |
DISABLE_SENTRY | Disable Sentry, not set automatically (defaults to false ) |
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.
The module caters to the following usage mechanisms:
withSentry
higher-order function.formatErrors
function (see below).serverless-sentry-lib
library.formatErrors
function to format and capture errors caught by GraphQL.handleErrorSentryOptions
to apply the above rules to your own Sentry
client.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.
formatErrors
function to handle errors caught by GraphQLimport { ApolloServer } from 'apollo-server-lambda';
import withSentry from 'serverless-sentry-lib';
import schema from '../graphql';
import { formatError } from '@beforeyoubid/error-adapter';
const server = new ApolloServer({
schema,
formatError,
context: async ({ event, context }): Promise<ApplicationContext> => {
const headers = {};
let gqcontext = {};
if (event.headers) {
const sourceUserAgent =
_.get(event, 'headers.x-source-user-agent') || _.get(event, 'headers.X-Source-User-Agent');
gqcontext = {
sourceUserAgent,
};
}
return {
// cache,
functionName: context.functionName,
headers,
...gqcontext,
};
},
});
const graphqlHandler = server.createHandler({
cors: {
origin: '*',
methods: ['POST'],
},
});
export default withSentry(graphqlHandler);
handleErrorSentryOptions
to apply the above rules to your own Sentry
client.Using handleErrorSentryOptions
function to send errors to Sentry by passing handleErrorSentryOptions
function into
Lambda GraphQL handler.
import { ApolloServer } from 'apollo-server-lambda';
import withSentry from 'serverless-sentry-lib';
import schema from '../graphql';
import { formatError, handleErrorSentryOptions } from '@beforeyoubid/error-adapter';
const server = new ApolloServer({
schema,
formatError,
context: async ({ event, context }): Promise<ApplicationContext> => {
const headers = {};
let gqcontext = {};
if (event.headers) {
const sourceUserAgent =
_.get(event, 'headers.x-source-user-agent') || _.get(event, 'headers.X-Source-User-Agent');
gqcontext = {
sourceUserAgent,
};
}
return {
// cache,
functionName: context.functionName,
headers,
...gqcontext,
};
},
});
const graphqlHandler = server.createHandler({
cors: {
origin: '*',
methods: ['POST'],
},
});
export default withSentry(handleErrorSentryOptions, graphqlHandler);
import withSentry from 'serverless-sentry-lib';
import { handleErrorSentryOptions, NotFound } from '@beforeyoubid/error-adapter';
export const cronHandler = withSentry(handleErrorSentryOptions, async (event, context) => {
console.log('EVENT: \n' + JSON.stringify(event, null, 2));
throw new Error('This error will be raised in Sentry');
return context.logStreamName;
});
FAQs
A module to standardize error handling across the BYB platform
We found that @beforeyoubid/error-adapter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
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.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.