|
1 | 1 | "use strict"
|
2 |
| -import axios from "axios" |
| 2 | +import axios, { isAxiosError } from "axios" |
3 | 3 | import { getAuthenticatedUser } from "coder/site/src/api/api"
|
| 4 | +import { getErrorMessage } from "coder/site/src/api/errors" |
4 | 5 | import fs from "fs"
|
5 | 6 | import * as https from "https"
|
6 | 7 | import * as module from "module"
|
7 | 8 | import * as os from "os"
|
8 | 9 | import * as vscode from "vscode"
|
9 | 10 | import { Commands } from "./commands"
|
10 |
| -import { CertificateError } from "./error" |
| 11 | +import { CertificateError, getErrorDetail } from "./error" |
11 | 12 | import { Remote } from "./remote"
|
12 | 13 | import { Storage } from "./storage"
|
13 | 14 | import { WorkspaceQuery, WorkspaceProvider } from "./workspacesProvider"
|
@@ -199,13 +200,38 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
|
199 | 200 | try {
|
200 | 201 | await remote.setup(vscodeProposed.env.remoteAuthority)
|
201 | 202 | } catch (ex) {
|
202 |
| - if (ex instanceof CertificateError) { |
203 |
| - return await ex.showModal("Failed to open workspace") |
| 203 | + switch (true) { |
| 204 | + case ex instanceof CertificateError: |
| 205 | + await ex.showModal("Failed to open workspace") |
| 206 | + break |
| 207 | + case isAxiosError(ex): |
| 208 | + { |
| 209 | + const msg = getErrorMessage(ex, "") |
| 210 | + const detail = getErrorDetail(ex) |
| 211 | + const urlString = axios.getUri(ex.response?.config) |
| 212 | + let path = urlString |
| 213 | + try { |
| 214 | + path = new URL(urlString).pathname |
| 215 | + } catch (e) { |
| 216 | + // ignore, default to full url |
| 217 | + } |
| 218 | + |
| 219 | + await vscodeProposed.window.showErrorMessage("Failed to open workspace", { |
| 220 | + detail: `API ${ex.response?.config.method?.toUpperCase()} to '${path}' failed with code ${ex.response?.status}.\nMessage: ${msg}\nDetail: ${detail}`, |
| 221 | + modal: true, |
| 222 | + useCustom: true, |
| 223 | + }) |
| 224 | + } |
| 225 | + break |
| 226 | + default: |
| 227 | + await vscodeProposed.window.showErrorMessage("Failed to open workspace", { |
| 228 | + detail: (ex as string).toString(), |
| 229 | + modal: true, |
| 230 | + useCustom: true, |
| 231 | + }) |
204 | 232 | }
|
205 |
| - await vscodeProposed.window.showErrorMessage("Failed to open workspace", { |
206 |
| - detail: (ex as string).toString(), |
207 |
| - modal: true, |
208 |
| - useCustom: true, |
209 |
| - }) |
| 233 | + |
| 234 | + // Always close remote session when we fail to open a workspace. |
| 235 | + await remote.closeRemote() |
210 | 236 | }
|
211 | 237 | }
|
0 commit comments