Skip to content

Commit 07caef5

Browse files
committed
Improve error reporting for passthrough, with event tags & debug info
1 parent e9e77a9 commit 07caef5

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/server/mockttp-server.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,8 +1241,18 @@ ${await this.suggestRule(request)}`
12411241
});
12421242
}
12431243

1244-
socket.on('error', () => upstreamSocket.destroy());
1245-
upstreamSocket.on('error', () => socket.destroy());
1244+
socket.on('error', (e: any) => {
1245+
if (this.debug) console.warn(`Downstream ${type} passthrough error to ${hostname}:${targetPort}:`, e);
1246+
eventData.tags.push(`${type}-passthrough-error:${e.code || 'UNKNOWN'}`);
1247+
upstreamSocket.destroy();
1248+
});
1249+
1250+
upstreamSocket.on('error', (e) => {
1251+
if (this.debug) console.warn(`Upstream ${type} passthrough error to ${hostname}:${targetPort}:`, e);
1252+
eventData.tags.push(`${type}-passthrough-error:${e.code || 'UNKNOWN'}`);
1253+
socket.destroy()
1254+
});
1255+
12461256
upstreamSocket.on('close', () => socket.destroy());
12471257
socket.on('close', () => {
12481258
upstreamSocket.destroy();

0 commit comments

Comments
 (0)