Skip to content

Commit 3b15310

Browse files
authored
fix(proxy): show friendly error when proxy config is not supported COMPASS-8345 (#6321)
* chore: show friendly error when proxy config is not supported * chore: fix log * chore: fix eslint checks
1 parent a06e469 commit 3b15310

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

packages/compass/src/main/application.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import './disable-node-deprecations'; // Separate module so it runs first
22
import path from 'path';
33
import { EventEmitter } from 'events';
44
import type { BrowserWindow, Event, ProxyConfig } from 'electron';
5+
import { dialog } from 'electron';
56
import { app, safeStorage, session } from 'electron';
67
import { ipcMain } from 'hadron-ipc';
78
import type { AutoUpdateManagerState } from './auto-update-manager';
@@ -301,7 +302,41 @@ class CompassApplication {
301302
try {
302303
const proxyOptions = proxyPreferenceToProxyOptions(value);
303304
await app.whenReady();
304-
await target.setProxy(translateToElectronProxyConfig(proxyOptions));
305+
306+
try {
307+
const electronProxyConfig =
308+
translateToElectronProxyConfig(proxyOptions);
309+
await target.setProxy(electronProxyConfig);
310+
} catch (err) {
311+
const headline = String(
312+
err && typeof err === 'object' && 'message' in err
313+
? err.message
314+
: err ||
315+
'Currently Compass does not support authenticated or ssh proxies.'
316+
);
317+
318+
log.warn(
319+
mongoLogId(1_001_000_332),
320+
logContext,
321+
'Unable to set proxy configuration',
322+
{
323+
error: headline,
324+
}
325+
);
326+
327+
const sep = path.sep;
328+
const configPath = `${app.getPath(
329+
'userData'
330+
)}${sep}AppPreferences${sep}General.json`;
331+
332+
dialog.showErrorBox(
333+
'Unsupported proxy configuration',
334+
`${headline}\n\n
335+
To reset the proxy configuration, remove the "proxy" key in ${configPath} and restart Compass.`
336+
);
337+
338+
app.quit();
339+
}
305340

306341
const agent = createAgent(proxyOptions);
307342
const fetch = createFetch(agent || {});

0 commit comments

Comments
 (0)