Skip to content

Commit

Permalink
Rename SelfSignedCertificateError to CertificateError
Browse files Browse the repository at this point in the history
This class will handle various certificate errors.
  • Loading branch information
code-asher committed Aug 1, 2023
1 parent 19d6bbe commit 5f03ca3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
10 changes: 5 additions & 5 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getAuthenticatedUser, getWorkspaces, updateWorkspaceVersion } from "cod
import { Workspace, WorkspaceAgent } from "coder/site/src/api/typesGenerated"
import * as vscode from "vscode"
import { extractAgents } from "./api-helper"
import { SelfSignedCertificateError } from "./error"
import { CertificateError } from "./error"
import { Remote } from "./remote"
import { Storage } from "./storage"
import { OpenableTreeItem } from "./workspacesProvider"
Expand Down Expand Up @@ -62,8 +62,8 @@ export class Commands {
if (axios.isAxiosError(err) && err.response?.data) {
message = err.response.data.detail
}
if (err instanceof SelfSignedCertificateError) {
err.showInsecureNotification()
if (err instanceof CertificateError) {
err.showNotification()

return {
message: err.message,
Expand Down Expand Up @@ -199,8 +199,8 @@ export class Commands {
quickPick.busy = false
})
.catch((ex) => {
if (ex instanceof SelfSignedCertificateError) {
ex.showInsecureNotification()
if (ex instanceof CertificateError) {
ex.showNotification()
}
return
})
Expand Down
14 changes: 7 additions & 7 deletions src/error.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from "vscode"

export class SelfSignedCertificateError extends Error {
export class CertificateError extends Error {
public static Notification =
"Your Coder deployment is using a self-signed certificate. VS Code uses a version of Electron that does not support registering self-signed intermediate certificates with extensions."
public static ActionAllowInsecure = "Allow Insecure"
Expand All @@ -20,17 +20,17 @@ export class SelfSignedCertificateError extends Error {
vscode.window.showInformationMessage(CertificateError.InsecureMessage)
}

public async showInsecureNotification(): Promise<void> {
public async showNotification(): Promise<void> {
const value = await vscode.window.showErrorMessage(
SelfSignedCertificateError.Notification,
SelfSignedCertificateError.ActionAllowInsecure,
SelfSignedCertificateError.ActionViewMoreDetails,
CertificateError.Notification,
CertificateError.ActionAllowInsecure,
CertificateError.ActionViewMoreDetails,
)
if (value === SelfSignedCertificateError.ActionViewMoreDetails) {
if (value === CertificateError.ActionViewMoreDetails) {
await this.viewMoreDetails()
return
}
if (value === SelfSignedCertificateError.ActionAllowInsecure) {
if (value === CertificateError.ActionAllowInsecure) {
return this.allowInsecure()
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as https from "https"
import * as module from "module"
import * as vscode from "vscode"
import { Commands } from "./commands"
import { SelfSignedCertificateError } from "./error"
import { CertificateError } from "./error"
import { Remote } from "./remote"
import { Storage } from "./storage"
import { WorkspaceQuery, WorkspaceProvider } from "./workspacesProvider"
Expand Down Expand Up @@ -49,7 +49,7 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
if (err) {
const msg = err.toString() as string
if (msg.indexOf("unable to verify the first certificate") !== -1) {
throw new SelfSignedCertificateError(msg)
throw new CertificateError(msg)
}
}

Expand Down Expand Up @@ -144,23 +144,23 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
try {
await remote.setup(vscodeProposed.env.remoteAuthority)
} catch (ex) {
if (ex instanceof SelfSignedCertificateError) {
if (ex instanceof CertificateError) {
const prompt = await vscodeProposed.window.showErrorMessage(
"Failed to open workspace",
{
detail: SelfSignedCertificateError.Notification,
detail: CertificateError.Notification,
modal: true,
useCustom: true,
},
SelfSignedCertificateError.ActionAllowInsecure,
SelfSignedCertificateError.ActionViewMoreDetails,
CertificateError.ActionAllowInsecure,
CertificateError.ActionViewMoreDetails,
)
if (prompt === SelfSignedCertificateError.ActionAllowInsecure) {
if (prompt === CertificateError.ActionAllowInsecure) {
await ex.allowInsecure(storage)
await remote.reloadWindow()
return
}
if (prompt === SelfSignedCertificateError.ActionViewMoreDetails) {
if (prompt === CertificateError.ActionViewMoreDetails) {
await ex.viewMoreDetails()
return
}
Expand Down

0 comments on commit 5f03ca3

Please sign in to comment.