Skip to content

Commit 35afca9

Browse files
committed
improve error handling
1 parent dc5b9c4 commit 35afca9

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

Coder-Desktop/Coder-Desktop/URLHandler.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Foundation
2+
import SwiftUI
23
import VPNLib
34

45
@MainActor
@@ -29,32 +30,36 @@ class URLHandler {
2930

3031
switch route {
3132
case let .open(workspace, agent, type):
32-
switch type {
33-
case let .rdp(creds):
34-
try handleRDP(workspace: workspace, agent: agent, creds: creds)
33+
do {
34+
switch type {
35+
case let .rdp(creds):
36+
try handleRDP(workspace: workspace, agent: agent, creds: creds)
37+
}
38+
} catch {
39+
throw .openError(error)
3540
}
3641
}
3742
}
3843

39-
private func handleRDP(workspace: String, agent: String, creds: RDPCredentials) throws(URLError) {
44+
private func handleRDP(workspace: String, agent: String, creds: RDPCredentials) throws(OpenError) {
4045
guard vpn.state == .connected else {
41-
throw .openError(.coderConnectOffline)
46+
throw .coderConnectOffline
4247
}
4348

4449
guard let workspace = vpn.menuState.findWorkspace(name: workspace) else {
45-
throw .openError(.invalidWorkspace(workspace: workspace))
50+
throw .invalidWorkspace(workspace: workspace)
4651
}
4752

4853
guard let agent = vpn.menuState.findAgent(workspaceID: workspace.id, name: agent) else {
49-
throw .openError(.invalidAgent(workspace: workspace.name, agent: agent))
54+
throw .invalidAgent(workspace: workspace.name, agent: agent)
5055
}
5156

5257
var rdpString = "rdp:full address=s:\(agent.primaryHost):3389"
5358
if let username = creds.username {
5459
rdpString += "&username=s:\(username)"
5560
}
5661
guard let url = URL(string: rdpString) else {
57-
throw .openError(.couldNotCreateRDPURL(rdpString))
62+
throw .couldNotCreateRDPURL(rdpString)
5863
}
5964

6065
let alert = NSAlert()

Coder-Desktop/VPNLib/CoderRouter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public enum RouterError: Error {
3434
case noSession
3535
case openError(OpenError)
3636

37-
var description: String {
37+
public var description: String {
3838
switch self {
3939
case let .invalidAuthority(authority):
4040
"Authority '\(authority)' does not match the host of the current Coder deployment."
@@ -47,7 +47,7 @@ public enum RouterError: Error {
4747
}
4848
}
4949

50-
var localizedDescription: String { description }
50+
public var localizedDescription: String { description }
5151
}
5252

5353
public enum OpenError: Error {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy