Skip to content

Commit 5923769

Browse files
committed
Avoid logging in when no url has been set
To avoid an error like "127.0.0.1:80 ECONNREFUSED". Before we did not log the error so this did not matter so much but now we do to catch header issues.
1 parent 37118f9 commit 5923769

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

src/extension.ts

+21-16
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,28 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
7373
vscode.window.registerTreeDataProvider("myWorkspaces", myWorkspacesProvider)
7474
vscode.window.registerTreeDataProvider("allWorkspaces", allWorkspacesProvider)
7575

76-
getAuthenticatedUser()
77-
.then(async (user) => {
78-
if (user) {
79-
vscode.commands.executeCommand("setContext", "coder.authenticated", true)
80-
if (user.roles.find((role) => role.name === "owner")) {
81-
await vscode.commands.executeCommand("setContext", "coder.isOwner", true)
76+
const url = storage.getURL()
77+
if (url) {
78+
getAuthenticatedUser()
79+
.then(async (user) => {
80+
if (user) {
81+
vscode.commands.executeCommand("setContext", "coder.authenticated", true)
82+
if (user.roles.find((role) => role.name === "owner")) {
83+
await vscode.commands.executeCommand("setContext", "coder.isOwner", true)
84+
}
8285
}
83-
}
84-
})
85-
.catch((error) => {
86-
// This should be a failure to make the request, like the header command
87-
// errored.
88-
vscodeProposed.window.showErrorMessage("Failed to check user authentication: " + error.message)
89-
})
90-
.finally(() => {
91-
vscode.commands.executeCommand("setContext", "coder.loaded", true)
92-
})
86+
})
87+
.catch((error) => {
88+
// This should be a failure to make the request, like the header command
89+
// errored.
90+
vscodeProposed.window.showErrorMessage("Failed to check user authentication: " + error.message)
91+
})
92+
.finally(() => {
93+
vscode.commands.executeCommand("setContext", "coder.loaded", true)
94+
})
95+
} else {
96+
vscode.commands.executeCommand("setContext", "coder.loaded", true)
97+
}
9398

9499
vscode.window.registerUriHandler({
95100
handleUri: async (uri) => {

0 commit comments

Comments
 (0)