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://f6775276f60042bea6d5e951ca1d0e91@sentry.io/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 ( ) ;
133
144import { Command , flags } from '@oclif/command'
155import { 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://f6775276f60042bea6d5e951ca1d0e91@sentry.io/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'
44import { GraphQLScalarType } from 'graphql' ;
55
66import { HtkConfig } from './config' ;
7+ import { reportError } from './error-tracking' ;
78import { buildInterceptors , Interceptor } from './interceptors' ;
89
910const packageJson = require ( '../package.json' ) ;
@@ -85,10 +86,18 @@ const buildResolvers = (
8586
8687 Interceptor : {
8788 isActivable : ( interceptor : Interceptor ) => {
88- return interceptor . isActivable ( ) ;
89+ return interceptor . isActivable ( ) . catch ( ( e ) => {
90+ reportError ( e ) ;
91+ return false ;
92+ } ) ;
8993 } ,
9094 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+ }
92101 }
93102 } ,
94103
You can’t perform that action at this time.
0 commit comments