@beforeyoubid/error-adapter
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -5,2 +5,3 @@ declare enum ErrorCode { | ||
NOT_FOUND_ERROR = "not_found_error", | ||
DOWNSTREAM_SERVICE_ERROR = "DOWNSTREAM_SERVICE_ERROR", | ||
VALIDATION_ERROR = "validation_error", | ||
@@ -10,17 +11,3 @@ BAD_USER_INPUT = "bad_user_input_error", | ||
PAYMENT_ERROR = "payment_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" | ||
SERVER_ERROR = "server_error" | ||
} | ||
@@ -27,0 +14,0 @@ declare const errorTypesForSentry: ErrorCode[]; |
@@ -9,2 +9,3 @@ "use strict"; | ||
ErrorCode["NOT_FOUND_ERROR"] = "not_found_error"; | ||
ErrorCode["DOWNSTREAM_SERVICE_ERROR"] = "DOWNSTREAM_SERVICE_ERROR"; | ||
ErrorCode["VALIDATION_ERROR"] = "validation_error"; | ||
@@ -14,38 +15,8 @@ ErrorCode["BAD_USER_INPUT"] = "bad_user_input_error"; | ||
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.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, | ||
]; | ||
const errorTypesForSentry = [ErrorCode.AUTHORIZATION_ERROR, ErrorCode.SERVER_ERROR]; | ||
exports.errorTypesForSentry = errorTypesForSentry; | ||
const errorTypesToIncludeDetails = [ErrorCode.VALIDATION_ERROR]; | ||
exports.errorTypesToIncludeDetails = errorTypesToIncludeDetails; |
@@ -1,4 +0,3 @@ | ||
import { UserInputError } from 'apollo-server-errors'; | ||
import { UserInputError } from 'apollo-server-core'; | ||
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 { | ||
@@ -8,2 +7,4 @@ } | ||
} | ||
export declare class DownstreamServiceError extends Error { | ||
} | ||
export declare class NotAuthenticated extends Error { | ||
@@ -17,10 +18,7 @@ } | ||
} | ||
export declare class ExternalApiError extends Error { | ||
} | ||
export declare class SystemError extends Error { | ||
} | ||
export { UserInputError }; | ||
/** | ||
* Used to correctly format GraphQL errors to prepare for sending to Sentry if required | ||
* Used to correctly format GraphQL errors to prepare for sending to Sentry | ||
*/ | ||
declare const formatError: (error: GraphQLError) => GraphQLFormattedError; | ||
export { formatError, UserInputError, ActivityLogError, PermanentActivityLogError, APIFailureActivityLogError, MissingFieldActivityLogError, ExternalAPIAuthenticationFailActivityLogError, MissingExternalResourceActivityLogError, InternalAPIFailureActivityLogError, EmailActivityLogError, SMSActivityLogError, DBActivityLogError, RedisActivityLogError, InvestorOptOutActivityError, }; | ||
export { formatError }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
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.NotFound = exports.NotAuthorized = void 0; | ||
exports.formatError = exports.UserInputError = exports.ValidationError = exports.PaymentError = exports.ConflictError = exports.NotAuthenticated = exports.DownstreamServiceError = exports.NotFound = exports.NotAuthorized = void 0; | ||
const sentry_1 = require("./sentry"); | ||
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 apollo_server_core_1 = require("apollo-server-core"); | ||
Object.defineProperty(exports, "UserInputError", { enumerable: true, get: function () { return apollo_server_core_1.UserInputError; } }); | ||
const constants_1 = require("./constants"); | ||
const utils_1 = require("./utils"); | ||
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; } }); | ||
// Initialise the Sentry client | ||
sentry_1.Sentry.initialise(); | ||
/* tslint:disable */ | ||
@@ -30,2 +18,5 @@ class NotAuthorized extends Error { | ||
exports.NotFound = NotFound; | ||
class DownstreamServiceError extends Error { | ||
} | ||
exports.DownstreamServiceError = DownstreamServiceError; | ||
class NotAuthenticated extends Error { | ||
@@ -43,29 +34,14 @@ } | ||
exports.ValidationError = ValidationError; | ||
class ExternalApiError extends Error { | ||
} | ||
exports.ExternalApiError = ExternalApiError; | ||
class SystemError extends Error { | ||
} | ||
exports.SystemError = SystemError; | ||
/** | ||
* Used to correctly format GraphQL errors to prepare for sending to Sentry if required | ||
* Used to correctly format GraphQL errors to prepare for sending to Sentry | ||
*/ | ||
const formatError = (error) => { | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
const err = (_a = error.originalError) !== null && _a !== void 0 ? _a : error; | ||
var _a; | ||
console.log('this is error'); | ||
const err = error.originalError ? error.originalError : error; | ||
// console.log('testing2222'); | ||
let details; | ||
const code = utils_1.convertErrorToCode(err); | ||
// 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((_c = (_b = err) === null || _b === void 0 ? void 0 : _b.message) !== null && _c !== void 0 ? _c : ''); | ||
const stack = (_f = (_e = (_d = err.extensions) === null || _d === void 0 ? void 0 : _d.exception) === null || _e === void 0 ? void 0 : _e.stacktrace) !== null && _f !== void 0 ? _f : []; | ||
er.stack = stack.join('\n'); | ||
sentry_1.Sentry.captureException(er, { | ||
extra: Object.assign(Object.assign({}, ((_g = err.extensions) !== null && _g !== void 0 ? _g : {})), ((_h = error.extensions) !== null && _h !== void 0 ? _h : {})), | ||
}); | ||
} | ||
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); | ||
if (constants_1.errorTypesToIncludeDetails.includes(code)) { | ||
@@ -76,4 +52,4 @@ details = error.message; | ||
return Object.assign(Object.assign({}, error), { extensions: Object.assign(Object.assign({}, error.extensions), { code, | ||
details }) }); | ||
details, has_sent_to_sentry: true }) }); | ||
}; | ||
exports.formatError = formatError; |
@@ -1,5 +0,3 @@ | ||
import { ErrorCode } from './constants'; | ||
import { NotAuthorized, NotFound, NotAuthenticated, ConflictError, PaymentError, ValidationError, UserInputError, ExternalApiError, SystemError, formatError, ActivityLogError, PermanentActivityLogError, APIFailureActivityLogError, MissingFieldActivityLogError, ExternalAPIAuthenticationFailActivityLogError, MissingExternalResourceActivityLogError, InternalAPIFailureActivityLogError, EmailActivityLogError, SMSActivityLogError, DBActivityLogError, RedisActivityLogError, InvestorOptOutActivityError } from './errors'; | ||
import { NotAuthorized, NotFound, NotAuthenticated, DownstreamServiceError, ConflictError, PaymentError, ValidationError, UserInputError, formatError } from './errors'; | ||
import { handleErrorSentryOptions, Sentry, withSentry } from './sentry'; | ||
import { convertErrorToCode, isSentryLevelError } from './utils'; | ||
export { Sentry, withSentry, NotAuthorized, NotFound, NotAuthenticated, ConflictError, PaymentError, ValidationError, UserInputError, ExternalApiError, SystemError, ActivityLogError, PermanentActivityLogError, APIFailureActivityLogError, MissingFieldActivityLogError, ExternalAPIAuthenticationFailActivityLogError, MissingExternalResourceActivityLogError, InternalAPIFailureActivityLogError, EmailActivityLogError, SMSActivityLogError, DBActivityLogError, RedisActivityLogError, InvestorOptOutActivityError, formatError, handleErrorSentryOptions, isSentryLevelError, ErrorCode, convertErrorToCode, }; | ||
export { Sentry, withSentry, NotAuthorized, NotFound, NotAuthenticated, DownstreamServiceError, ConflictError, PaymentError, ValidationError, UserInputError, formatError, handleErrorSentryOptions, }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
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.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; } }); | ||
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; | ||
const errors_1 = require("./errors"); | ||
@@ -10,2 +8,3 @@ Object.defineProperty(exports, "NotAuthorized", { enumerable: true, get: function () { return errors_1.NotAuthorized; } }); | ||
Object.defineProperty(exports, "NotAuthenticated", { enumerable: true, get: function () { return errors_1.NotAuthenticated; } }); | ||
Object.defineProperty(exports, "DownstreamServiceError", { enumerable: true, get: function () { return errors_1.DownstreamServiceError; } }); | ||
Object.defineProperty(exports, "ConflictError", { enumerable: true, get: function () { return errors_1.ConflictError; } }); | ||
@@ -15,17 +14,3 @@ Object.defineProperty(exports, "PaymentError", { enumerable: true, get: function () { return errors_1.PaymentError; } }); | ||
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"); | ||
@@ -35,4 +20,1 @@ 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; } }); |
@@ -1,2 +0,1 @@ | ||
import { handleBeforeSend } from './sentry'; | ||
import { Sentry } from './node'; | ||
@@ -10,6 +9,6 @@ import withSentry from './serverless'; | ||
beforeSend: (_event: any, hint: { | ||
originalException: Error; | ||
originalException: Error | import("graphql").GraphQLError; | ||
}) => any; | ||
}; | ||
}; | ||
export { handleErrorSentryOptions, Sentry, withSentry, handleBeforeSend }; | ||
export { handleErrorSentryOptions, Sentry, withSentry }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.handleBeforeSend = exports.withSentry = exports.Sentry = exports.handleErrorSentryOptions = void 0; | ||
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"); | ||
@@ -7,0 +6,0 @@ Object.defineProperty(exports, "Sentry", { enumerable: true, get: function () { return node_1.Sentry; } }); |
@@ -1,10 +0,2 @@ | ||
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 }; | ||
declare let Sentry: any; | ||
export { Sentry }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Sentry = void 0; | ||
const Sentry = require("@sentry/node"); | ||
let Sentry = require('@sentry/node'); | ||
exports.Sentry = Sentry; | ||
const utils_1 = require("../utils"); | ||
let isSentryInitialised = false; | ||
const sentryParams = utils_1.getSentryParams(); | ||
let initialised = false; | ||
/** | ||
* Initialise Sentry based on provided options | ||
* @param options | ||
* Initialise Sentry based on provided parameters | ||
* @param 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); | ||
const initialise = (params = sentryParams) => { | ||
if (!initialised) { | ||
const { sentryOptions, sendToSentry } = params; | ||
if (sendToSentry) { | ||
@@ -23,8 +23,5 @@ Sentry.init(sentryOptions); | ||
} | ||
isSentryInitialised = true; | ||
initialised = true; | ||
}; | ||
// attach custom initialise function | ||
const SentryWithInitialise = Object.assign({}, Sentry !== null && Sentry !== void 0 ? Sentry : {}, { | ||
initialise, | ||
}); | ||
exports.Sentry = SentryWithInitialise; | ||
Sentry.initialise = initialise; |
@@ -0,1 +1,2 @@ | ||
import { GraphQLError } from 'graphql'; | ||
/** | ||
@@ -5,4 +6,4 @@ * Determine which errors are sent to Sentry based on error type | ||
declare const handleBeforeSend: (_event: any, hint: { | ||
originalException: Error; | ||
originalException: Error | GraphQLError; | ||
}) => any; | ||
export { handleBeforeSend }; |
@@ -10,5 +10,14 @@ "use strict"; | ||
const handleBeforeSend = (_event, hint) => { | ||
var _a, _b, _c; | ||
const { originalException: error } = hint; | ||
const code = utils_1.convertErrorToCode(error); | ||
if (!constants_1.errorTypesForSentry.includes(code)) { | ||
console.log('This is event', _event); | ||
console.log('This is hint', hint); | ||
let code = utils_1.convertErrorToCode(error); | ||
// if code not found, attempt to find the code from error.extensions.code | ||
// default to server error if not found | ||
if (!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 | ||
} | ||
if (!constants_1.errorTypesForSentry.includes(code) || ((_c = error.extensions) === null || _c === void 0 ? void 0 : _c.has_sent_to_sentry)) { | ||
return null; | ||
@@ -15,0 +24,0 @@ } |
@@ -1,7 +0,5 @@ | ||
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 function withSentry(options: WithSentryOptions, handler: Handler<any, any>): Handler<any, any>; | ||
declare function withSentry(handler: Handler<any, any>): Handler<any, any>; | ||
declare const withSentry: (arg1: object, arg2?: any) => any; | ||
export default withSentry; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const serverless_sentry_lib_1 = require("serverless-sentry-lib"); | ||
let serverlessSentry = require('serverless-sentry-lib'); | ||
const node_1 = require("../node"); | ||
const isArgOptions = (arg) => typeof arg === 'object'; | ||
const isArgHandler = (arg) => typeof arg === 'function'; | ||
function withSentry(arg1, arg2) { | ||
if (isArgOptions(arg1) && arg2 !== undefined && isArgHandler(arg2)) { | ||
// 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') { | ||
// custom options passed in, include in callback | ||
// this allows the use of serverless-sentry-lib to handle custom options | ||
return serverless_sentry_lib_1.default(arg1, arg2); | ||
return serverlessSentry(arg1, arg2); | ||
} | ||
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); | ||
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); | ||
} | ||
@@ -21,3 +23,3 @@ else { | ||
} | ||
} | ||
}; | ||
exports.default = withSentry; |
@@ -11,3 +11,3 @@ /// <reference types="node" /> | ||
}; | ||
declare const getDefaultSentryParams: (env?: NodeJS.ProcessEnv) => ISentryParams; | ||
declare const getSentryParams: (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 { getDefaultSentryParams, getEnvs, isSentryEnabled }; | ||
export { getSentryParams, getEnvs, isSentryEnabled }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isSentryEnabled = exports.getEnvs = exports.getDefaultSentryParams = void 0; | ||
exports.isSentryEnabled = exports.getEnvs = exports.getSentryParams = 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 getDefaultSentryParams = (env = (process === null || process === void 0 ? void 0 : process.env) || {}) => { | ||
const getSentryParams = (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 defaultSentryOptions = { | ||
const sentryOptions = { | ||
dsn: SENTRY_DSN, | ||
environment: SENTRY_ENVIRONMENT, | ||
sampleRate: Number(SENTRY_SAMPLE_RATE), | ||
sampleRate: SENTRY_SAMPLE_RATE, | ||
beforeSend: sentry_1.handleBeforeSend, | ||
@@ -28,6 +28,6 @@ }; | ||
sendToSentry: isSentryEnabled(SENTRY_DSN, STAGE, SENTRY_FILTER_LOCAL, DISABLE_SENTRY), | ||
defaultSentryOptions, | ||
sentryOptions, | ||
}; | ||
}; | ||
exports.getDefaultSentryParams = getDefaultSentryParams; | ||
exports.getSentryParams = getSentryParams; | ||
/** | ||
@@ -34,0 +34,0 @@ * Handy function to check if we are sending to Sentry |
@@ -1,5 +0,10 @@ | ||
import { NodeOptions } from '@sentry/node'; | ||
export interface ISentryOptions { | ||
dsn: string; | ||
environment: string; | ||
sampleRate: string | number; | ||
beforeSend: any; | ||
} | ||
export interface ISentryParams { | ||
sendToSentry: boolean; | ||
defaultSentryOptions: NodeOptions; | ||
sentryOptions: ISentryOptions; | ||
} |
@@ -1,16 +0,6 @@ | ||
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; | ||
/** | ||
* 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 }; | ||
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 }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isSentryLevelError = exports.getErrorType = exports.convertErrorToCode = void 0; | ||
exports.convertErrorToCode = void 0; | ||
const errors_1 = require("./errors"); | ||
@@ -26,96 +26,8 @@ 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: | ||
return constants_1.ErrorCode.DOWNSTREAM_SERVICE_ERROR; | ||
default: | ||
return constants_1.ErrorCode.SERVER_ERROR; | ||
return null; | ||
} | ||
}; | ||
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) => { | ||
const code = convertErrorToCode(error); | ||
return constants_1.errorTypesForSentry.includes(code); | ||
}; | ||
exports.isSentryLevelError = isSentryLevelError; |
{ | ||
"name": "@beforeyoubid/error-adapter", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "A module to standardize error handling across the BYB platform", | ||
@@ -14,6 +14,6 @@ "main": "dist/index.js", | ||
"lint:fix": "eslint --fix --max-warnings 0 '**/*.{ts,tsx,js,jsx}'", | ||
"test": "yarn build && yarn jest --config jestconfig.json", | ||
"test:coverage": "yarn build && yarn jest --config jestconfig.json --watch --coverage", | ||
"test:ci": "yarn build && yarn jest --config jestconfig.json --verbose=false --coverage", | ||
"test-only": "jest --config jestconfig.json", | ||
"test": "yarn build && jest --config jest.config.js", | ||
"test:coverage": "yarn build && jest --config jest.config.js --watch --coverage", | ||
"test:ci": "yarn build && jest --config jest.config.js --verbose=false --coverage", | ||
"test-only": "jest --config jest.config.js", | ||
"build": "tsc", | ||
@@ -20,0 +20,0 @@ "build-and-publish": "npm run build && npm publish --access public" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28275
384
1