diff --git a/package.json b/package.json index ce5464dc..9e64fe03 100644 --- a/package.json +++ b/package.json @@ -40,10 +40,12 @@ }, "dependencies": { "@txo/log": "^2.0.16", + "@txo/service-prop": "^3.0.3", "@txo/types": "^1.7.0" }, "peerDependencies": { "@sentry/react-native": "^5.35.0", + "@txo-peer-dep/error-handler": "^3.1.0", "@txo-peer-dep/log": "^4.0.4", "@txo-peer-dep/observable-redux": "^2.0.1", "@txo-peer-dep/redux": "^1.0.1", @@ -55,6 +57,7 @@ "@babel/preset-env": "^7.26.0", "@react-navigation/native": "^6.1.18", "@sentry/react-native": "^5.35.0", + "@txo-peer-dep/error-handler": "^3.1.0", "@txo-peer-dep/log": "^4.0.4", "@txo-peer-dep/observable-redux": "^2.0.1", "@txo-peer-dep/redux": "^1.0.1", diff --git a/src/Api/ErrorListener.ts b/src/Api/ErrorListener.ts new file mode 100644 index 00000000..81ba17b8 --- /dev/null +++ b/src/Api/ErrorListener.ts @@ -0,0 +1,36 @@ +/** + * @Author: Erik Slovak + * @Date: 2024-11-29T20:43:00+01:00 + * @Copyright: Technology Studio +**/ + +import { + ServiceOperationError, + containsNonNetworkError, +} from '@txo/service-prop' +import { + subscribeErrorListener, + VALIDATION_ERROR, +} from '@txo-peer-dep/error-handler' +import * as Sentry from '@sentry/react-native' + +export const subscribeSentryErrorListener = (): () => void => ( + subscribeErrorListener((error) => { + if (error instanceof ServiceOperationError) { + const areErrorsValidationOnly = error.serviceErrorList.every(error => ( + error.meta?.type === VALIDATION_ERROR + )) + if (containsNonNetworkError(error) || !areErrorsValidationOnly) { + Sentry.withScope(scope => { + scope.setExtra('serviceErrorList', error.serviceErrorList) + scope.setExtra('context', error.context) + scope.setExtra('operationName', error.operationName) + + Sentry.captureException(error) + }) + } + } else { + Sentry.captureException(error) + } + }) +) diff --git a/src/index.ts b/src/index.ts index 8346db85..14590e5a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,7 @@ * @Copyright: Technology Studio **/ +export * from './Api/ErrorListener' export * from './Api/SentryBreadcrumbErrorLink' export * from './Api/SentryHelper' export * from './Api/SentryInit' diff --git a/yarn.lock b/yarn.lock index c2dabd7a..824fc581 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2486,6 +2486,13 @@ "@tufjs/canonical-json" "2.0.0" minimatch "^9.0.3" +"@txo-peer-dep/error-handler@^3.1.0": + version "3.1.0" + resolved "https://registry.yarnpkg.com/@txo-peer-dep/error-handler/-/error-handler-3.1.0.tgz#3225c7c425ffe1a845208998b2bdeb201e50bf84" + integrity sha512-LjQZTxFz/JVORg1Aa01hL/AGxeep4+G4tupOh0ANKqnI+aLR03COX9MsCFlZAg4OInNELqYrHNCO+KFj4Uvoag== + dependencies: + "@txo/log" "^2.0.16" + "@txo-peer-dep/log@^4.0.4": version "4.0.4" resolved "https://registry.yarnpkg.com/@txo-peer-dep/log/-/log-4.0.4.tgz#73611601423b0ec5c134964419bd642a61bd1b56" @@ -2538,6 +2545,13 @@ semantic-release "^23.1.1" semantic-release-slack-bot "^4.0.2" +"@txo/service-prop@^3.0.3": + version "3.0.3" + resolved "https://registry.yarnpkg.com/@txo/service-prop/-/service-prop-3.0.3.tgz#f8518ec014131358e9e531eba6812f3bedc79f83" + integrity sha512-Rt9GVlVXrMFFdK+x36rF86p5IUid49ez4s+aaow4CtMz6KF+j2mEeNvbhqa60Q8rFrwQVbprveXGKWH4EQGnOg== + dependencies: + "@txo/types" "^1.7.0" + "@txo/tsconfig-cjs@^2.0.0": version "2.0.0" resolved "https://registry.yarnpkg.com/@txo/tsconfig-cjs/-/tsconfig-cjs-2.0.0.tgz#e5a323a4723a4050015e777181f4057770cd2e6a"