Skip to content

Commit 42aa8f4

Browse files
authored
feat: add sentry error listener (#1031)
* feat: add sentry error listener * fix: remove unnecessary dependency and update import
1 parent 443d366 commit 42aa8f4

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@
4040
},
4141
"dependencies": {
4242
"@txo/log": "^2.0.16",
43+
"@txo/service-prop": "^3.0.3",
4344
"@txo/types": "^1.7.0"
4445
},
4546
"peerDependencies": {
4647
"@sentry/react-native": "^5.35.0",
48+
"@txo-peer-dep/error-handler": "^3.1.0",
4749
"@txo-peer-dep/log": "^4.0.4",
4850
"@txo-peer-dep/observable-redux": "^2.0.1",
4951
"@txo-peer-dep/redux": "^1.0.1",
@@ -55,6 +57,7 @@
5557
"@babel/preset-env": "^7.26.0",
5658
"@react-navigation/native": "^6.1.18",
5759
"@sentry/react-native": "^5.35.0",
60+
"@txo-peer-dep/error-handler": "^3.1.0",
5861
"@txo-peer-dep/log": "^4.0.4",
5962
"@txo-peer-dep/observable-redux": "^2.0.1",
6063
"@txo-peer-dep/redux": "^1.0.1",

src/Api/ErrorListener.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @Author: Erik Slovak <[email protected]>
3+
* @Date: 2024-11-29T20:43:00+01:00
4+
* @Copyright: Technology Studio
5+
**/
6+
7+
import {
8+
ServiceOperationError,
9+
containsNonNetworkError,
10+
} from '@txo/service-prop'
11+
import {
12+
subscribeErrorListener,
13+
VALIDATION_ERROR,
14+
} from '@txo-peer-dep/error-handler'
15+
import * as Sentry from '@sentry/react-native'
16+
17+
export const subscribeSentryErrorListener = (): () => void => (
18+
subscribeErrorListener((error) => {
19+
if (error instanceof ServiceOperationError) {
20+
const areErrorsValidationOnly = error.serviceErrorList.every(error => (
21+
error.meta?.type === VALIDATION_ERROR
22+
))
23+
if (containsNonNetworkError(error) || !areErrorsValidationOnly) {
24+
Sentry.withScope(scope => {
25+
scope.setExtra('serviceErrorList', error.serviceErrorList)
26+
scope.setExtra('context', error.context)
27+
scope.setExtra('operationName', error.operationName)
28+
29+
Sentry.captureException(error)
30+
})
31+
}
32+
} else {
33+
Sentry.captureException(error)
34+
}
35+
})
36+
)

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* @Copyright: Technology Studio
55
**/
66

7+
export * from './Api/ErrorListener'
78
export * from './Api/SentryBreadcrumbErrorLink'
89
export * from './Api/SentryHelper'
910
export * from './Api/SentryInit'

yarn.lock

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2486,6 +2486,13 @@
24862486
"@tufjs/canonical-json" "2.0.0"
24872487
minimatch "^9.0.3"
24882488

2489+
"@txo-peer-dep/error-handler@^3.1.0":
2490+
version "3.1.0"
2491+
resolved "https://registry.yarnpkg.com/@txo-peer-dep/error-handler/-/error-handler-3.1.0.tgz#3225c7c425ffe1a845208998b2bdeb201e50bf84"
2492+
integrity sha512-LjQZTxFz/JVORg1Aa01hL/AGxeep4+G4tupOh0ANKqnI+aLR03COX9MsCFlZAg4OInNELqYrHNCO+KFj4Uvoag==
2493+
dependencies:
2494+
"@txo/log" "^2.0.16"
2495+
24892496
"@txo-peer-dep/log@^4.0.4":
24902497
version "4.0.4"
24912498
resolved "https://registry.yarnpkg.com/@txo-peer-dep/log/-/log-4.0.4.tgz#73611601423b0ec5c134964419bd642a61bd1b56"
@@ -2538,6 +2545,13 @@
25382545
semantic-release "^23.1.1"
25392546
semantic-release-slack-bot "^4.0.2"
25402547

2548+
"@txo/service-prop@^3.0.3":
2549+
version "3.0.3"
2550+
resolved "https://registry.yarnpkg.com/@txo/service-prop/-/service-prop-3.0.3.tgz#f8518ec014131358e9e531eba6812f3bedc79f83"
2551+
integrity sha512-Rt9GVlVXrMFFdK+x36rF86p5IUid49ez4s+aaow4CtMz6KF+j2mEeNvbhqa60Q8rFrwQVbprveXGKWH4EQGnOg==
2552+
dependencies:
2553+
"@txo/types" "^1.7.0"
2554+
25412555
"@txo/tsconfig-cjs@^2.0.0":
25422556
version "2.0.0"
25432557
resolved "https://registry.yarnpkg.com/@txo/tsconfig-cjs/-/tsconfig-cjs-2.0.0.tgz#e5a323a4723a4050015e777181f4057770cd2e6a"

0 commit comments

Comments
 (0)