Skip to content

Commit

Permalink
feat: add useSentryException hook (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardodouradol authored Jun 18, 2024
1 parent 22e878a commit 8703d45
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"coverage": "TZ=UTC+3 jest --coverage"
},
"dependencies": {
"@sentry/react": "^8.9.2",
"react": "^18.2.0"
},
"devDependencies": {
Expand Down
19 changes: 19 additions & 0 deletions src/hooks/useSentryException.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as Sentry from '@sentry/react';

interface CaptureExceptionOptions {
component: string;
clientId: string;
}

const useSentryException = (
error: Error,
{ component, clientId }: CaptureExceptionOptions,
): void => {
Sentry.withScope((scope: Sentry.Scope) => {
scope.setTag('component', component);
scope.setTag('clientId', clientId);
Sentry.captureException(error);
});
};

export default useSentryException;
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// hooks
export { default as useOnScreen } from './hooks/useOnScreen';
export { default as useSentryException } from './hooks/useSentryException';

// normalizers
export { default as normalizeMoney } from './normalizers/normalizeMoney';
Expand Down

0 comments on commit 8703d45

Please sign in to comment.