File tree Expand file tree Collapse file tree 3 files changed +41
-14
lines changed Expand file tree Collapse file tree 3 files changed +41
-14
lines changed Original file line number Diff line number Diff line change 1
- import * as Sentry from '@sentry/node' ;
2
-
3
- const packageJson = require ( '../../package.json' ) ;
4
- let { SENTRY_DSN } = process . env ;
5
- if ( ! SENTRY_DSN && process . env . HTTPTOOLKIT_SERVER_BINPATH ) {
6
- // If we're a built binary, use the standard DSN automatically
7
- SENTRY_DSN = 'https://[email protected] /1371158' ;
8
- }
9
-
10
- if ( SENTRY_DSN ) {
11
- Sentry . init ( { dsn : SENTRY_DSN , release : packageJson . version } ) ;
12
- }
1
+ import { initErrorTracking } from '../error-tracking' ;
2
+ initErrorTracking ( ) ;
13
3
14
4
import { Command , flags } from '@oclif/command'
15
5
import { runHTK } from '../index' ;
Original file line number Diff line number Diff line change
1
+ import * as Sentry from '@sentry/node' ;
2
+
3
+ let sentryInitialized = false ;
4
+
5
+ export function initErrorTracking ( ) {
6
+ const packageJson = require ( '../package.json' ) ;
7
+ let { SENTRY_DSN } = process . env ;
8
+ if ( ! SENTRY_DSN && process . env . HTTPTOOLKIT_SERVER_BINPATH ) {
9
+ // If we're a built binary, use the standard DSN automatically
10
+ SENTRY_DSN = 'https://[email protected] /1371158' ;
11
+ }
12
+
13
+ if ( SENTRY_DSN ) {
14
+ Sentry . init ( { dsn : SENTRY_DSN , release : packageJson . version } ) ;
15
+ sentryInitialized = true ;
16
+ }
17
+ }
18
+
19
+ export function reportError ( error : Error | string ) {
20
+ console . warn ( error ) ;
21
+ if ( ! sentryInitialized ) return ;
22
+
23
+ if ( typeof error === 'string' ) {
24
+ Sentry . captureMessage ( error ) ;
25
+ } else {
26
+ Sentry . captureException ( error ) ;
27
+ }
28
+ }
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { GraphQLServer } from 'graphql-yoga'
4
4
import { GraphQLScalarType } from 'graphql' ;
5
5
6
6
import { HtkConfig } from './config' ;
7
+ import { reportError } from './error-tracking' ;
7
8
import { buildInterceptors , Interceptor } from './interceptors' ;
8
9
9
10
const packageJson = require ( '../package.json' ) ;
@@ -85,10 +86,18 @@ const buildResolvers = (
85
86
86
87
Interceptor : {
87
88
isActivable : ( interceptor : Interceptor ) => {
88
- return interceptor . isActivable ( ) ;
89
+ return interceptor . isActivable ( ) . catch ( ( e ) => {
90
+ reportError ( e ) ;
91
+ return false ;
92
+ } ) ;
89
93
} ,
90
94
isActive : ( interceptor : Interceptor , args : _ . Dictionary < any > ) => {
91
- return interceptor . isActive ( args . proxyPort ) ;
95
+ try {
96
+ return interceptor . isActive ( args . proxyPort ) ;
97
+ } catch ( e ) {
98
+ reportError ( e ) ;
99
+ return false ;
100
+ }
92
101
}
93
102
} ,
94
103
You can’t perform that action at this time.
0 commit comments