Skip to content

Commit 3259816

Browse files
committed
Return clear errors when failing to activate an interceptor
1 parent 3877cd3 commit 3259816

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/httptoolkit-server.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,21 @@ const buildResolvers = (interceptors: _.Dictionary<Interceptor>) => {
4747
Mutation: {
4848
activateInterceptor: async (__: void, args: _.Dictionary<any>) => {
4949
const { id, proxyPort, options } = args;
50-
await interceptors[id].activate(proxyPort, options);
51-
return interceptors[id].isActive(proxyPort);
50+
51+
const interceptor = interceptors[id];
52+
if (!interceptor) throw new Error(`Unknown interceptor ${id}`);
53+
54+
await interceptor.activate(proxyPort, options);
55+
return interceptor.isActive(proxyPort);
5256
},
5357
deactivateInterceptor: async (__: void, args: _.Dictionary<any>) => {
5458
const { id, proxyPort, options } = args;
55-
await interceptors[id].deactivate(proxyPort, options);
56-
return !interceptors[id].isActive(proxyPort);
59+
60+
const interceptor = interceptors[id];
61+
if (!interceptor) throw new Error(`Unknown interceptor ${id}`);
62+
63+
await interceptor.deactivate(proxyPort, options);
64+
return !interceptor.isActive(proxyPort);
5765
}
5866
},
5967

0 commit comments

Comments
 (0)