Socket
Socket
Sign inDemoInstall

@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 - npm Package Compare versions

Comparing version 1.1.4 to 1.1.5

dist/activity-log-errors.d.ts

16

dist/constants.d.ts

@@ -10,3 +10,17 @@ declare enum ErrorCode {

PAYMENT_ERROR = "payment_error",
SERVER_ERROR = "server_error"
EXTERNAL_API_ERROR = "external_api_error",
SYSTEM_ERROR = "system_error",
SERVER_ERROR = "server_error",
ACTIVITY_LOG_ERROR = "activity",
PERMANENT_ACTIVITY_LOG_ERROR = "permanent",
API_FAILURE_ACTIVITY_LOG_ERROR = "api_failure",
MISSING_FIELD_ACTIVITY_LOG_ERROR = "missing_field",
EXTERNAL_API_AUTHENTICATION_FAIL_ACTIVITY_LOG_ERROR = "api_auth_failure",
MISSING_EXTERNAL_RESOURCE_ACTIVITY_LOG_ERROR = "missing_external_resource",
INTERNAL_API_FAILURE_ACTIVITY_LOG_ERROR = "internal_api_failure",
EMAIL_ACTIVITY_LOG_ERROR = "email_failure",
SMS_ACTIVITY_LOG_ERROR = "sms_failure",
DB_ACTIVITY_LOG_ERROR = "db_failure",
REDIS_ACTIVITY_LOG_ERROR = "redis_failure",
INVESTOR_OPT_OUT_ACTIVITY_LOG_ERROR = "investor_opt_out"
}

@@ -13,0 +27,0 @@ declare const errorTypesForSentry: ErrorCode[];

@@ -14,8 +14,38 @@ "use strict";

ErrorCode["PAYMENT_ERROR"] = "payment_error";
ErrorCode["EXTERNAL_API_ERROR"] = "external_api_error";
ErrorCode["SYSTEM_ERROR"] = "system_error";
ErrorCode["SERVER_ERROR"] = "server_error";
// from byb-investors-api service
ErrorCode["ACTIVITY_LOG_ERROR"] = "activity";
ErrorCode["PERMANENT_ACTIVITY_LOG_ERROR"] = "permanent";
ErrorCode["API_FAILURE_ACTIVITY_LOG_ERROR"] = "api_failure";
ErrorCode["MISSING_FIELD_ACTIVITY_LOG_ERROR"] = "missing_field";
ErrorCode["EXTERNAL_API_AUTHENTICATION_FAIL_ACTIVITY_LOG_ERROR"] = "api_auth_failure";
ErrorCode["MISSING_EXTERNAL_RESOURCE_ACTIVITY_LOG_ERROR"] = "missing_external_resource";
ErrorCode["INTERNAL_API_FAILURE_ACTIVITY_LOG_ERROR"] = "internal_api_failure";
ErrorCode["EMAIL_ACTIVITY_LOG_ERROR"] = "email_failure";
ErrorCode["SMS_ACTIVITY_LOG_ERROR"] = "sms_failure";
ErrorCode["DB_ACTIVITY_LOG_ERROR"] = "db_failure";
ErrorCode["REDIS_ACTIVITY_LOG_ERROR"] = "redis_failure";
ErrorCode["INVESTOR_OPT_OUT_ACTIVITY_LOG_ERROR"] = "investor_opt_out";
})(ErrorCode || (ErrorCode = {}));
exports.ErrorCode = ErrorCode;
const errorTypesForSentry = [ErrorCode.AUTHORIZATION_ERROR, ErrorCode.SERVER_ERROR];
const errorTypesForSentry = [
ErrorCode.AUTHORIZATION_ERROR,
ErrorCode.EXTERNAL_API_ERROR,
ErrorCode.SYSTEM_ERROR,
ErrorCode.SERVER_ERROR,
// from byb-investors-api service
ErrorCode.API_FAILURE_ACTIVITY_LOG_ERROR,
ErrorCode.MISSING_FIELD_ACTIVITY_LOG_ERROR,
ErrorCode.EXTERNAL_API_AUTHENTICATION_FAIL_ACTIVITY_LOG_ERROR,
ErrorCode.MISSING_EXTERNAL_RESOURCE_ACTIVITY_LOG_ERROR,
ErrorCode.INTERNAL_API_FAILURE_ACTIVITY_LOG_ERROR,
ErrorCode.EMAIL_ACTIVITY_LOG_ERROR,
ErrorCode.SMS_ACTIVITY_LOG_ERROR,
ErrorCode.DB_ACTIVITY_LOG_ERROR,
ErrorCode.REDIS_ACTIVITY_LOG_ERROR,
];
exports.errorTypesForSentry = errorTypesForSentry;
const errorTypesToIncludeDetails = [ErrorCode.VALIDATION_ERROR];
exports.errorTypesToIncludeDetails = errorTypesToIncludeDetails;

10

dist/errors.d.ts

@@ -1,3 +0,4 @@

import { UserInputError } from 'apollo-server-core';
import { UserInputError } from 'apollo-server-errors';
import { GraphQLError, GraphQLFormattedError } from 'graphql';
import { ActivityLogError, PermanentActivityLogError, APIFailureActivityLogError, MissingFieldActivityLogError, ExternalAPIAuthenticationFailActivityLogError, MissingExternalResourceActivityLogError, InternalAPIFailureActivityLogError, EmailActivityLogError, SMSActivityLogError, DBActivityLogError, RedisActivityLogError, InvestorOptOutActivityError } from './activity-log-errors';
export declare class NotAuthorized extends Error {

@@ -17,3 +18,6 @@ }

}
export { UserInputError };
export declare class ExternalApiError extends Error {
}
export declare class SystemError extends Error {
}
/**

@@ -23,2 +27,2 @@ * Used to correctly format GraphQL errors to prepare for sending to Sentry

declare const formatError: (error: GraphQLError) => GraphQLFormattedError;
export { formatError };
export { formatError, UserInputError, ActivityLogError, PermanentActivityLogError, APIFailureActivityLogError, MissingFieldActivityLogError, ExternalAPIAuthenticationFailActivityLogError, MissingExternalResourceActivityLogError, InternalAPIFailureActivityLogError, EmailActivityLogError, SMSActivityLogError, DBActivityLogError, RedisActivityLogError, InvestorOptOutActivityError, };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatError = exports.UserInputError = exports.ValidationError = exports.PaymentError = exports.ConflictError = exports.NotAuthenticated = exports.DownstreamServiceError = exports.NotFound = exports.NotAuthorized = void 0;
exports.InvestorOptOutActivityError = exports.RedisActivityLogError = exports.DBActivityLogError = exports.SMSActivityLogError = exports.EmailActivityLogError = exports.InternalAPIFailureActivityLogError = exports.MissingExternalResourceActivityLogError = exports.ExternalAPIAuthenticationFailActivityLogError = exports.MissingFieldActivityLogError = exports.APIFailureActivityLogError = exports.PermanentActivityLogError = exports.ActivityLogError = exports.UserInputError = exports.formatError = exports.SystemError = exports.ExternalApiError = exports.ValidationError = exports.PaymentError = exports.ConflictError = exports.NotAuthenticated = exports.DownstreamServiceError = exports.NotFound = exports.NotAuthorized = void 0;
const sentry_1 = require("./sentry");
const apollo_server_core_1 = require("apollo-server-core");
Object.defineProperty(exports, "UserInputError", { enumerable: true, get: function () { return apollo_server_core_1.UserInputError; } });
const apollo_server_errors_1 = require("apollo-server-errors");
Object.defineProperty(exports, "UserInputError", { enumerable: true, get: function () { return apollo_server_errors_1.UserInputError; } });
const graphql_1 = require("graphql");
const constants_1 = require("./constants");
const utils_1 = require("./utils");
// Initialise the Sentry client
sentry_1.Sentry.initialise();
const activity_log_errors_1 = require("./activity-log-errors");
Object.defineProperty(exports, "ActivityLogError", { enumerable: true, get: function () { return activity_log_errors_1.ActivityLogError; } });
Object.defineProperty(exports, "PermanentActivityLogError", { enumerable: true, get: function () { return activity_log_errors_1.PermanentActivityLogError; } });
Object.defineProperty(exports, "APIFailureActivityLogError", { enumerable: true, get: function () { return activity_log_errors_1.APIFailureActivityLogError; } });
Object.defineProperty(exports, "MissingFieldActivityLogError", { enumerable: true, get: function () { return activity_log_errors_1.MissingFieldActivityLogError; } });
Object.defineProperty(exports, "ExternalAPIAuthenticationFailActivityLogError", { enumerable: true, get: function () { return activity_log_errors_1.ExternalAPIAuthenticationFailActivityLogError; } });
Object.defineProperty(exports, "MissingExternalResourceActivityLogError", { enumerable: true, get: function () { return activity_log_errors_1.MissingExternalResourceActivityLogError; } });
Object.defineProperty(exports, "InternalAPIFailureActivityLogError", { enumerable: true, get: function () { return activity_log_errors_1.InternalAPIFailureActivityLogError; } });
Object.defineProperty(exports, "EmailActivityLogError", { enumerable: true, get: function () { return activity_log_errors_1.EmailActivityLogError; } });
Object.defineProperty(exports, "SMSActivityLogError", { enumerable: true, get: function () { return activity_log_errors_1.SMSActivityLogError; } });
Object.defineProperty(exports, "DBActivityLogError", { enumerable: true, get: function () { return activity_log_errors_1.DBActivityLogError; } });
Object.defineProperty(exports, "RedisActivityLogError", { enumerable: true, get: function () { return activity_log_errors_1.RedisActivityLogError; } });
Object.defineProperty(exports, "InvestorOptOutActivityError", { enumerable: true, get: function () { return activity_log_errors_1.InvestorOptOutActivityError; } });
/* tslint:disable */

@@ -33,2 +45,8 @@ class NotAuthorized extends Error {

exports.ValidationError = ValidationError;
class ExternalApiError extends Error {
}
exports.ExternalApiError = ExternalApiError;
class SystemError extends Error {
}
exports.SystemError = SystemError;
/**

@@ -38,10 +56,19 @@ * Used to correctly format GraphQL errors to prepare for sending to Sentry

const formatError = (error) => {
var _a;
console.log('this is error');
const err = error.originalError ? error.originalError : error;
// console.log('testing2222');
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
const err = (_a = error.originalError) !== null && _a !== void 0 ? _a : error;
let details;
let code = (_a = utils_1.convertErrorToCode(err)) !== null && _a !== void 0 ? _a : constants_1.ErrorCode.SERVER_ERROR;
// Sentry client will determine if the error is to be reported to Sentry
sentry_1.Sentry.captureException(err);
const code = (_b = utils_1.convertErrorToCode(err)) !== null && _b !== void 0 ? _b : constants_1.ErrorCode.SERVER_ERROR;
// Error will be a GraphQL error if formatting error using a GraphQL Federation
if (err instanceof Error && !(err instanceof graphql_1.GraphQLError)) {
sentry_1.Sentry.captureException(err);
}
else {
const typeOfError = utils_1.getErrorType(err);
const er = new typeOfError((_d = (_c = err) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : '');
const stack = (_g = (_f = (_e = err.extensions) === null || _e === void 0 ? void 0 : _e.exception) === null || _f === void 0 ? void 0 : _f.stacktrace) !== null && _g !== void 0 ? _g : [];
er.stack = stack.join('\n');
sentry_1.Sentry.captureException(er, {
extra: Object.assign(Object.assign({}, ((_h = err.extensions) !== null && _h !== void 0 ? _h : {})), ((_j = error.extensions) !== null && _j !== void 0 ? _j : {})),
});
}
if (constants_1.errorTypesToIncludeDetails.includes(code)) {

@@ -48,0 +75,0 @@ details = error.message;

@@ -1,3 +0,5 @@

import { NotAuthorized, NotFound, NotAuthenticated, DownstreamServiceError, ConflictError, PaymentError, ValidationError, UserInputError, formatError } from './errors';
import { ErrorCode } from './constants';
import { NotAuthorized, NotFound, NotAuthenticated, DownstreamServiceError, ConflictError, PaymentError, ValidationError, UserInputError, ExternalApiError, SystemError, formatError, ActivityLogError, PermanentActivityLogError, APIFailureActivityLogError, MissingFieldActivityLogError, ExternalAPIAuthenticationFailActivityLogError, MissingExternalResourceActivityLogError, InternalAPIFailureActivityLogError, EmailActivityLogError, SMSActivityLogError, DBActivityLogError, RedisActivityLogError, InvestorOptOutActivityError } from './errors';
import { handleErrorSentryOptions, Sentry, withSentry } from './sentry';
export { Sentry, withSentry, NotAuthorized, NotFound, NotAuthenticated, DownstreamServiceError, ConflictError, PaymentError, ValidationError, UserInputError, formatError, handleErrorSentryOptions, };
import { convertErrorToCode, isSentryLevelError } from './utils';
export { Sentry, withSentry, NotAuthorized, NotFound, NotAuthenticated, DownstreamServiceError, ConflictError, PaymentError, ValidationError, UserInputError, ExternalApiError, SystemError, ActivityLogError, PermanentActivityLogError, APIFailureActivityLogError, MissingFieldActivityLogError, ExternalAPIAuthenticationFailActivityLogError, MissingExternalResourceActivityLogError, InternalAPIFailureActivityLogError, EmailActivityLogError, SMSActivityLogError, DBActivityLogError, RedisActivityLogError, InvestorOptOutActivityError, formatError, handleErrorSentryOptions, isSentryLevelError, ErrorCode, convertErrorToCode, };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleErrorSentryOptions = exports.formatError = exports.UserInputError = exports.ValidationError = exports.PaymentError = exports.ConflictError = exports.DownstreamServiceError = exports.NotAuthenticated = exports.NotFound = exports.NotAuthorized = exports.withSentry = exports.Sentry = void 0;
exports.convertErrorToCode = exports.ErrorCode = exports.isSentryLevelError = exports.handleErrorSentryOptions = exports.formatError = exports.InvestorOptOutActivityError = exports.RedisActivityLogError = exports.DBActivityLogError = exports.SMSActivityLogError = exports.EmailActivityLogError = exports.InternalAPIFailureActivityLogError = exports.MissingExternalResourceActivityLogError = exports.ExternalAPIAuthenticationFailActivityLogError = exports.MissingFieldActivityLogError = exports.APIFailureActivityLogError = exports.PermanentActivityLogError = exports.ActivityLogError = exports.SystemError = exports.ExternalApiError = exports.UserInputError = exports.ValidationError = exports.PaymentError = exports.ConflictError = exports.DownstreamServiceError = exports.NotAuthenticated = exports.NotFound = exports.NotAuthorized = exports.withSentry = exports.Sentry = void 0;
const constants_1 = require("./constants");
Object.defineProperty(exports, "ErrorCode", { enumerable: true, get: function () { return constants_1.ErrorCode; } });
const errors_1 = require("./errors");

@@ -13,3 +15,17 @@ Object.defineProperty(exports, "NotAuthorized", { enumerable: true, get: function () { return errors_1.NotAuthorized; } });

Object.defineProperty(exports, "UserInputError", { enumerable: true, get: function () { return errors_1.UserInputError; } });
Object.defineProperty(exports, "ExternalApiError", { enumerable: true, get: function () { return errors_1.ExternalApiError; } });
Object.defineProperty(exports, "SystemError", { enumerable: true, get: function () { return errors_1.SystemError; } });
Object.defineProperty(exports, "formatError", { enumerable: true, get: function () { return errors_1.formatError; } });
Object.defineProperty(exports, "ActivityLogError", { enumerable: true, get: function () { return errors_1.ActivityLogError; } });
Object.defineProperty(exports, "PermanentActivityLogError", { enumerable: true, get: function () { return errors_1.PermanentActivityLogError; } });
Object.defineProperty(exports, "APIFailureActivityLogError", { enumerable: true, get: function () { return errors_1.APIFailureActivityLogError; } });
Object.defineProperty(exports, "MissingFieldActivityLogError", { enumerable: true, get: function () { return errors_1.MissingFieldActivityLogError; } });
Object.defineProperty(exports, "ExternalAPIAuthenticationFailActivityLogError", { enumerable: true, get: function () { return errors_1.ExternalAPIAuthenticationFailActivityLogError; } });
Object.defineProperty(exports, "MissingExternalResourceActivityLogError", { enumerable: true, get: function () { return errors_1.MissingExternalResourceActivityLogError; } });
Object.defineProperty(exports, "InternalAPIFailureActivityLogError", { enumerable: true, get: function () { return errors_1.InternalAPIFailureActivityLogError; } });
Object.defineProperty(exports, "EmailActivityLogError", { enumerable: true, get: function () { return errors_1.EmailActivityLogError; } });
Object.defineProperty(exports, "SMSActivityLogError", { enumerable: true, get: function () { return errors_1.SMSActivityLogError; } });
Object.defineProperty(exports, "DBActivityLogError", { enumerable: true, get: function () { return errors_1.DBActivityLogError; } });
Object.defineProperty(exports, "RedisActivityLogError", { enumerable: true, get: function () { return errors_1.RedisActivityLogError; } });
Object.defineProperty(exports, "InvestorOptOutActivityError", { enumerable: true, get: function () { return errors_1.InvestorOptOutActivityError; } });
const sentry_1 = require("./sentry");

@@ -19,1 +35,4 @@ Object.defineProperty(exports, "handleErrorSentryOptions", { enumerable: true, get: function () { return sentry_1.handleErrorSentryOptions; } });

Object.defineProperty(exports, "withSentry", { enumerable: true, get: function () { return sentry_1.withSentry; } });
const utils_1 = require("./utils");
Object.defineProperty(exports, "convertErrorToCode", { enumerable: true, get: function () { return utils_1.convertErrorToCode; } });
Object.defineProperty(exports, "isSentryLevelError", { enumerable: true, get: function () { return utils_1.isSentryLevelError; } });

@@ -0,1 +1,2 @@

import { handleBeforeSend } from './sentry';
import { Sentry } from './node';

@@ -13,2 +14,2 @@ import withSentry from './serverless';

};
export { handleErrorSentryOptions, Sentry, withSentry };
export { handleErrorSentryOptions, Sentry, withSentry, handleBeforeSend };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.withSentry = exports.Sentry = exports.handleErrorSentryOptions = void 0;
exports.handleBeforeSend = exports.withSentry = exports.Sentry = exports.handleErrorSentryOptions = void 0;
const sentry_1 = require("./sentry");
Object.defineProperty(exports, "handleBeforeSend", { enumerable: true, get: function () { return sentry_1.handleBeforeSend; } });
const node_1 = require("./node");

@@ -6,0 +7,0 @@ Object.defineProperty(exports, "Sentry", { enumerable: true, get: function () { return node_1.Sentry; } });

@@ -1,2 +0,10 @@

declare let Sentry: any;
export { Sentry };
import * as Sentry from '@sentry/node';
/**
* Initialise Sentry based on provided options
* @param options
*/
declare const initialise: (options?: Sentry.NodeOptions | undefined) => void;
declare const SentryWithInitialise: typeof Sentry & {
initialise: typeof initialise;
};
export { SentryWithInitialise as Sentry };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Sentry = void 0;
let Sentry = require('@sentry/node');
exports.Sentry = Sentry;
const Sentry = require("@sentry/node");
const utils_1 = require("../utils");
const sentryParams = utils_1.getSentryParams();
let initialised = false;
let isSentryInitialised = false;
/**
* Initialise Sentry based on provided parameters
* @param params
* Initialise Sentry based on provided options
* @param options
*/
const initialise = (params = sentryParams) => {
if (!initialised) {
const { sentryOptions, sendToSentry } = params;
const initialise = (options) => {
if (!isSentryInitialised) {
const { defaultSentryOptions, sendToSentry } = utils_1.getDefaultSentryParams();
// replace defaulted options with options passed in if they exist
const sentryOptions = Object.assign(Object.assign({}, defaultSentryOptions), options);
if (sendToSentry) {

@@ -23,5 +23,8 @@ Sentry.init(sentryOptions);

}
initialised = true;
isSentryInitialised = true;
};
// attach custom initialise function
Sentry.initialise = initialise;
const SentryWithInitialise = Object.assign({}, Sentry !== null && Sentry !== void 0 ? Sentry : {}, {
initialise,
});
exports.Sentry = SentryWithInitialise;

@@ -12,4 +12,2 @@ "use strict";

const { originalException: error } = hint;
console.log('This is event', _event);
console.log('This is hint', hint);
let code = utils_1.convertErrorToCode(error);

@@ -20,3 +18,2 @@ // if code not found, attempt to find the code from error.extensions.code

code = (_b = (_a = error.extensions) === null || _a === void 0 ? void 0 : _a.code) !== null && _b !== void 0 ? _b : constants_1.ErrorCode.SERVER_ERROR;
// running in gateway
}

@@ -23,0 +20,0 @@ if (!constants_1.errorTypesForSentry.includes(code) || ((_c = error.extensions) === null || _c === void 0 ? void 0 : _c.has_sent_to_sentry)) {

@@ -0,5 +1,7 @@

import { WithSentryOptions, Handler } from 'serverless-sentry-lib';
/**
* Wrap the serverless-sentry-lib function call to default to using own Sentry client unless custom options provided
*/
declare const withSentry: (arg1: object, arg2?: any) => any;
declare function withSentry(options: WithSentryOptions, handler: Handler<any, any>): Handler<any, any>;
declare function withSentry(handler: Handler<any, any>): Handler<any, any>;
export default withSentry;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
let serverlessSentry = require('serverless-sentry-lib');
const serverless_sentry_lib_1 = require("serverless-sentry-lib");
const node_1 = require("../node");
// Initialise the Sentry client based on environment variables
node_1.Sentry.initialise();
/**
* Wrap the serverless-sentry-lib function call to default to using own Sentry client unless custom options provided
*/
const withSentry = (arg1, arg2) => {
if (typeof arg1 === 'object') {
const isArgOptions = (arg) => typeof arg === 'object';
const isArgHandler = (arg) => typeof arg === 'function';
function withSentry(arg1, arg2) {
if (isArgOptions(arg1) && arg2 !== undefined && isArgHandler(arg2)) {
// custom options passed in, include in callback
// this allows the use of serverless-sentry-lib to handle custom options
return serverlessSentry(arg1, arg2);
return serverless_sentry_lib_1.default(arg1, arg2);
}
else if (typeof arg1 === 'function') {
// no custom options, pass in pre-initialised Sentry client, arg1 is the callback function
return serverlessSentry({ sentry: node_1.Sentry }, arg1);
else if (isArgHandler(arg1)) {
// no custom options, intialise and pass in Sentry client, arg1 is the callback function
node_1.Sentry.initialise();
return serverless_sentry_lib_1.default({ sentry: node_1.Sentry }, arg1);
}

@@ -23,3 +21,3 @@ else {

}
};
}
exports.default = withSentry;

@@ -11,3 +11,3 @@ /// <reference types="node" />

};
declare const getSentryParams: (env?: NodeJS.ProcessEnv) => ISentryParams;
declare const getDefaultSentryParams: (env?: NodeJS.ProcessEnv) => ISentryParams;
/**

@@ -21,2 +21,2 @@ * Handy function to check if we are sending to Sentry

declare const isSentryEnabled: (sentryDSN: string, stage: string, filterLocal: string, disableSentry: string) => boolean;
export { getSentryParams, getEnvs, isSentryEnabled };
export { getDefaultSentryParams, getEnvs, isSentryEnabled };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isSentryEnabled = exports.getEnvs = exports.getSentryParams = void 0;
exports.isSentryEnabled = exports.getEnvs = exports.getDefaultSentryParams = void 0;
const sentry_1 = require("./sentry");

@@ -17,8 +17,8 @@ const getEnvs = (env = (process === null || process === void 0 ? void 0 : process.env) || {}) => {

exports.getEnvs = getEnvs;
const getSentryParams = (env = (process === null || process === void 0 ? void 0 : process.env) || {}) => {
const getDefaultSentryParams = (env = (process === null || process === void 0 ? void 0 : process.env) || {}) => {
const { SENTRY_DSN, SENTRY_ENVIRONMENT, SENTRY_FILTER_LOCAL, SENTRY_SAMPLE_RATE, DISABLE_SENTRY, STAGE } = getEnvs(env);
const sentryOptions = {
const defaultSentryOptions = {
dsn: SENTRY_DSN,
environment: SENTRY_ENVIRONMENT,
sampleRate: SENTRY_SAMPLE_RATE,
sampleRate: Number(SENTRY_SAMPLE_RATE),
beforeSend: sentry_1.handleBeforeSend,

@@ -28,6 +28,6 @@ };

sendToSentry: isSentryEnabled(SENTRY_DSN, STAGE, SENTRY_FILTER_LOCAL, DISABLE_SENTRY),
sentryOptions,
defaultSentryOptions,
};
};
exports.getSentryParams = getSentryParams;
exports.getDefaultSentryParams = getDefaultSentryParams;
/**

@@ -34,0 +34,0 @@ * Handy function to check if we are sending to Sentry

@@ -1,10 +0,5 @@

export interface ISentryOptions {
dsn: string;
environment: string;
sampleRate: string | number;
beforeSend: any;
}
import { NodeOptions } from '@sentry/node';
export interface ISentryParams {
sendToSentry: boolean;
sentryOptions: ISentryOptions;
defaultSentryOptions: NodeOptions;
}

@@ -0,6 +1,16 @@

import { UserInputError, ActivityLogError } from './errors';
import { ErrorCode } from './constants';
import { GraphQLError } from 'graphql';
/**
* Parse the error based on the error constructor
*/
declare const convertErrorToCode: (error: Error) => ErrorCode.AUTHENTICATION_ERROR | ErrorCode.AUTHORIZATION_ERROR | ErrorCode.NOT_FOUND_ERROR | ErrorCode.DOWNSTREAM_SERVICE_ERROR | ErrorCode.VALIDATION_ERROR | ErrorCode.BAD_USER_INPUT | ErrorCode.CONFLICT_ERROR | ErrorCode.PAYMENT_ERROR | null;
export { convertErrorToCode };
declare const convertErrorToCode: (error: Error) => ErrorCode.AUTHENTICATION_ERROR | ErrorCode.AUTHORIZATION_ERROR | ErrorCode.NOT_FOUND_ERROR | ErrorCode.DOWNSTREAM_SERVICE_ERROR | ErrorCode.VALIDATION_ERROR | ErrorCode.BAD_USER_INPUT | ErrorCode.CONFLICT_ERROR | ErrorCode.PAYMENT_ERROR | ErrorCode.EXTERNAL_API_ERROR | ErrorCode.SYSTEM_ERROR | ErrorCode.ACTIVITY_LOG_ERROR | ErrorCode.PERMANENT_ACTIVITY_LOG_ERROR | ErrorCode.API_FAILURE_ACTIVITY_LOG_ERROR | ErrorCode.MISSING_FIELD_ACTIVITY_LOG_ERROR | ErrorCode.EXTERNAL_API_AUTHENTICATION_FAIL_ACTIVITY_LOG_ERROR | ErrorCode.MISSING_EXTERNAL_RESOURCE_ACTIVITY_LOG_ERROR | ErrorCode.INTERNAL_API_FAILURE_ACTIVITY_LOG_ERROR | ErrorCode.EMAIL_ACTIVITY_LOG_ERROR | ErrorCode.SMS_ACTIVITY_LOG_ERROR | ErrorCode.DB_ACTIVITY_LOG_ERROR | ErrorCode.REDIS_ACTIVITY_LOG_ERROR | ErrorCode.INVESTOR_OPT_OUT_ACTIVITY_LOG_ERROR | null;
/**
* Return error type based on error code
*/
declare const getErrorType: (error: GraphQLError) => typeof ActivityLogError | typeof UserInputError;
/**
* Helper function to determine if an error is a Sentry level error
*/
declare const isSentryLevelError: (error: Error) => boolean;
export { convertErrorToCode, getErrorType, isSentryLevelError };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertErrorToCode = void 0;
exports.isSentryLevelError = exports.getErrorType = exports.convertErrorToCode = void 0;
const errors_1 = require("./errors");

@@ -26,2 +26,30 @@ const constants_1 = require("./constants");

return constants_1.ErrorCode.PAYMENT_ERROR;
case errors_1.ExternalApiError:
return constants_1.ErrorCode.EXTERNAL_API_ERROR;
case errors_1.SystemError:
return constants_1.ErrorCode.SYSTEM_ERROR;
case errors_1.ActivityLogError:
return constants_1.ErrorCode.ACTIVITY_LOG_ERROR;
case errors_1.PermanentActivityLogError:
return constants_1.ErrorCode.PERMANENT_ACTIVITY_LOG_ERROR;
case errors_1.APIFailureActivityLogError:
return constants_1.ErrorCode.API_FAILURE_ACTIVITY_LOG_ERROR;
case errors_1.MissingFieldActivityLogError:
return constants_1.ErrorCode.MISSING_FIELD_ACTIVITY_LOG_ERROR;
case errors_1.ExternalAPIAuthenticationFailActivityLogError:
return constants_1.ErrorCode.EXTERNAL_API_AUTHENTICATION_FAIL_ACTIVITY_LOG_ERROR;
case errors_1.MissingExternalResourceActivityLogError:
return constants_1.ErrorCode.MISSING_EXTERNAL_RESOURCE_ACTIVITY_LOG_ERROR;
case errors_1.InternalAPIFailureActivityLogError:
return constants_1.ErrorCode.INTERNAL_API_FAILURE_ACTIVITY_LOG_ERROR;
case errors_1.EmailActivityLogError:
return constants_1.ErrorCode.EMAIL_ACTIVITY_LOG_ERROR;
case errors_1.SMSActivityLogError:
return constants_1.ErrorCode.SMS_ACTIVITY_LOG_ERROR;
case errors_1.DBActivityLogError:
return constants_1.ErrorCode.DB_ACTIVITY_LOG_ERROR;
case errors_1.RedisActivityLogError:
return constants_1.ErrorCode.REDIS_ACTIVITY_LOG_ERROR;
case errors_1.InvestorOptOutActivityError:
return constants_1.ErrorCode.INVESTOR_OPT_OUT_ACTIVITY_LOG_ERROR;
case errors_1.DownstreamServiceError:

@@ -34,1 +62,64 @@ return constants_1.ErrorCode.DOWNSTREAM_SERVICE_ERROR;

exports.convertErrorToCode = convertErrorToCode;
/**
* Return error type based on error code
*/
const getErrorType = (error) => {
var _a;
const { code } = (_a = error.extensions) !== null && _a !== void 0 ? _a : {};
switch (code) {
case constants_1.ErrorCode.AUTHENTICATION_ERROR:
return errors_1.NotAuthenticated;
case constants_1.ErrorCode.AUTHORIZATION_ERROR:
return errors_1.NotAuthorized;
case constants_1.ErrorCode.NOT_FOUND_ERROR:
return errors_1.NotFound;
case constants_1.ErrorCode.VALIDATION_ERROR:
return errors_1.ValidationError;
case constants_1.ErrorCode.BAD_USER_INPUT:
return errors_1.UserInputError;
case constants_1.ErrorCode.CONFLICT_ERROR:
return errors_1.ConflictError;
case constants_1.ErrorCode.PAYMENT_ERROR:
return errors_1.PaymentError;
case constants_1.ErrorCode.EXTERNAL_API_ERROR:
return errors_1.ExternalApiError;
case constants_1.ErrorCode.SYSTEM_ERROR:
return errors_1.SystemError;
case constants_1.ErrorCode.ACTIVITY_LOG_ERROR:
return errors_1.ActivityLogError;
case constants_1.ErrorCode.PERMANENT_ACTIVITY_LOG_ERROR:
return errors_1.PermanentActivityLogError;
case constants_1.ErrorCode.API_FAILURE_ACTIVITY_LOG_ERROR:
return errors_1.APIFailureActivityLogError;
case constants_1.ErrorCode.MISSING_FIELD_ACTIVITY_LOG_ERROR:
return errors_1.MissingFieldActivityLogError;
case constants_1.ErrorCode.EXTERNAL_API_AUTHENTICATION_FAIL_ACTIVITY_LOG_ERROR:
return errors_1.ExternalAPIAuthenticationFailActivityLogError;
case constants_1.ErrorCode.MISSING_EXTERNAL_RESOURCE_ACTIVITY_LOG_ERROR:
return errors_1.MissingExternalResourceActivityLogError;
case constants_1.ErrorCode.INTERNAL_API_FAILURE_ACTIVITY_LOG_ERROR:
return errors_1.InternalAPIFailureActivityLogError;
case constants_1.ErrorCode.EMAIL_ACTIVITY_LOG_ERROR:
return errors_1.EmailActivityLogError;
case constants_1.ErrorCode.SMS_ACTIVITY_LOG_ERROR:
return errors_1.SMSActivityLogError;
case constants_1.ErrorCode.DB_ACTIVITY_LOG_ERROR:
return errors_1.DBActivityLogError;
case constants_1.ErrorCode.REDIS_ACTIVITY_LOG_ERROR:
return errors_1.RedisActivityLogError;
case constants_1.ErrorCode.INVESTOR_OPT_OUT_ACTIVITY_LOG_ERROR:
return errors_1.InvestorOptOutActivityError;
default:
return Error;
}
};
exports.getErrorType = getErrorType;
/**
* Helper function to determine if an error is a Sentry level error
*/
const isSentryLevelError = (error) => {
var _a;
const code = (_a = convertErrorToCode(error)) !== null && _a !== void 0 ? _a : constants_1.ErrorCode.SERVER_ERROR;
return constants_1.errorTypesForSentry.includes(code);
};
exports.isSentryLevelError = isSentryLevelError;
{
"name": "@beforeyoubid/error-adapter",
"version": "1.1.4",
"version": "1.1.5",
"description": "A module to standardize error handling across the BYB platform",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc