Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add useSentryException hook #28

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading