Skip to content

Commit

Permalink
Merge branch 'release/141.1.2-1'
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoreymendez committed May 3, 2024
2 parents 7c41d69 + 35730c7 commit dedd5ef
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Sources/NetworkProtection/Networking/NetworkProtectionClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,27 @@ public enum NetworkProtectionClientError: CustomNSError, NetworkProtectionErrorC
case .accessDenied: return 13
}
}

public var errorUserInfo: [String: Any] {
switch self {
case .failedToFetchLocationList(let error),
.failedToParseLocationListResponse(let error),
.failedToFetchServerList(let error),
.failedToParseServerListResponse(let error),
.failedToFetchRegisteredServers(let error),
.failedToParseRegisteredServersResponse(let error),
.failedToRedeemInviteCode(let error),
.failedToParseRedeemResponse(let error):
return [NSUnderlyingErrorKey: error as NSError]
case .failedToEncodeRegisterKeyRequest,
.failedToEncodeRedeemRequest,
.invalidInviteCode,
.failedToRetrieveAuthToken,
.invalidAuthToken,
.accessDenied:
return [:]
}
}
}

struct RegisterKeyRequestBody: Encodable {
Expand Down
31 changes: 30 additions & 1 deletion Sources/NetworkProtection/WireGuardKit/WireGuardAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum WireGuardAdapterErrorInvalidStateReason: String {
case updatedTunnelWhileStopped
}

public enum WireGuardAdapterError: Error {
public enum WireGuardAdapterError: CustomNSError {
/// Failure to locate tunnel file descriptor.
case cannotLocateTunnelFileDescriptor

Expand All @@ -28,6 +28,35 @@ public enum WireGuardAdapterError: Error {

/// Failure to start WireGuard backend.
case startWireGuardBackend(Int32)

public var errorCode: Int {
switch self {
case .cannotLocateTunnelFileDescriptor: return 100
case .invalidState: return 101
case .dnsResolution: return 102
case .setNetworkSettings: return 103
case .startWireGuardBackend: return 104
}
}

public var errorUserInfo: [String: Any] {
switch self {
case .cannotLocateTunnelFileDescriptor,
.invalidState:
return [:]
case .dnsResolution(let errors):
guard let firstError = errors.first else {
return [:]
}

return [NSUnderlyingErrorKey: firstError as NSError]
case .setNetworkSettings(let error):
return [NSUnderlyingErrorKey: error as NSError]
case .startWireGuardBackend(let code):
let error = NSError(domain: "startWireGuardBackend", code: Int(code))
return [NSUnderlyingErrorKey: error as NSError]
}
}
}

/// Enum representing internal state of the `WireGuardAdapter`
Expand Down

0 comments on commit dedd5ef

Please sign in to comment.