Skip to content

Commit 29a71c5

Browse files
committed
Report failed interceptor activations after 30s
1 parent 8308237 commit 29a71c5

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/error-tracking.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ export function initErrorTracking() {
5050
}
5151
}
5252

53+
export function addBreadcrumb(message: string, data: Sentry.Breadcrumb) {
54+
Sentry.addBreadcrumb(Object.assign({ message }, data));
55+
}
56+
5357
export function reportError(error: Error | string) {
5458
console.warn(error);
5559
if (!sentryInitialized) return;

src/httptoolkit-server.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import * as Express from 'express';
66
import { GraphQLScalarType } from 'graphql';
77

88
import { HtkConfig } from './config';
9-
import { reportError } from './error-tracking';
9+
import { reportError, addBreadcrumb } from './error-tracking';
1010
import { buildInterceptors, Interceptor } from './interceptors';
11-
import { ALLOWED_ORIGINS } from './util';
11+
import { ALLOWED_ORIGINS, delay } from './util';
1212

1313
const packageJson = require('../package.json');
1414

@@ -69,11 +69,25 @@ const buildResolvers = (
6969
activateInterceptor: async (__: void, args: _.Dictionary<any>) => {
7070
const { id, proxyPort, options } = args;
7171

72+
addBreadcrumb(`Activating ${id}`, { category: 'interceptor', data: { id, options } });
73+
7274
const interceptor = interceptors[id];
7375
if (!interceptor) throw new Error(`Unknown interceptor ${id}`);
7476

75-
await interceptor.activate(proxyPort, options);
76-
return interceptor.isActive(proxyPort);
77+
await Promise.race([
78+
interceptor.activate(proxyPort, options),
79+
delay(30000) // After 30s, we don't stop activating, but we do report failure
80+
]);
81+
82+
const isActive = interceptor.isActive(proxyPort);
83+
84+
if (isActive) {
85+
addBreadcrumb(`Successfully activated ${id}`, { category: 'interceptor' });
86+
} else {
87+
reportError(new Error(`Failed to activate ${id}`));
88+
}
89+
90+
return isActive;
7791
},
7892
deactivateInterceptor: async (__: void, args: _.Dictionary<any>) => {
7993
const { id, proxyPort, options } = args;

0 commit comments

Comments
 (0)