Skip to content

Commit

Permalink
ref: Handle all ts errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jennmueng committed Jul 7, 2020
1 parent fe9cb98 commit 9ee3cdb
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions packages/react/src/redux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,60 @@ export interface SentryMiddlewareOptions {
* Use this to remove any private data before sending it to Sentry.
* Return null to not attach the state.
*/
stateTransformer?(state: object | undefined): object | null;
// tslint:disable-next-line: no-null-undefined-union
stateTransformer(state: object | undefined): object | null | undefined;
/**
* Transforms the action before sending it as a breadcrumb.
* Use this to remove any private data before sending it to Sentry.
* Return null to not send the breadcrumb.
*/
actionTransformer?(action: Redux.Action): Redux.Action | null;
// tslint:disable-next-line: no-null-undefined-union
actionTransformer(action: Redux.Action): Redux.Action | null | undefined;
/**
* Category of the breadcrumb sent by actions. Default is 'redux.action'
*/
actionBreadcrumbCategory?: string;
actionBreadcrumbCategory: string;
/**
* Type of the breadcrumb sent by actions. Default is 'info'
*/
actionBreadcrumbType?: string;
actionBreadcrumbType: string;
/**
* The extra key to pass the state to. Default is 'redux.state'
*/
stateExtraKey?: string;
stateExtraKey: string;
/**
* Called on every state update, configure the Sentry Scope with the redux state.
*/
configureScopeWithState?(scope: Sentry.Scope, state: object | undefined): void;
}

const defaultOptions = {
const defaultOptions: SentryMiddlewareOptions = {
actionBreadcrumbCategory: 'redux.action',
actionBreadcrumbType: 'info',
actionTransformer: action => action,
stateExtraKey: 'redux.state',
stateTransformer: state => state,
};

function createReduxEnhancer(enhancerOptions: SentryMiddlewareOptions = defaultOptions): Redux.StoreEnhancer {
function createReduxEnhancer(enhancerOptions?: Partial<SentryMiddlewareOptions>): Redux.StoreEnhancer {
return next => (reducer, initialState) => {
const options = {
...defaultOptions,
...enhancerOptions,
};

const sentryReducer: Redux.Reducer<any, any> = (state, action) => {
const newState = reducer(state, action);
// tslint:disable-next-line: no-unsafe-any
const newState: any = reducer(state, action);

Sentry.configureScope(scope => {
/* Action breadcrumbs */
// tslint:disable-next-line: no-unsafe-any
const transformedAction = options.actionTransformer ? options.actionTransformer(action) : action;
if (typeof transformedAction !== 'undefined' && transformedAction !== null) {
scope.addBreadcrumb({
category: options.actionBreadcrumbCategory,
// tslint:disable-next-line: no-unsafe-any
data: transformedAction,
type: options.actionBreadcrumbType,
});
Expand All @@ -73,6 +78,7 @@ function createReduxEnhancer(enhancerOptions: SentryMiddlewareOptions = defaultO
/* Allow user to configure scope with latest state */
const { configureScopeWithState } = options;
if (typeof configureScopeWithState === 'function') {
// tslint:disable-next-line: no-unsafe-any
configureScopeWithState(scope, newState);
}
});
Expand Down

0 comments on commit 9ee3cdb

Please sign in to comment.