mirror of
https://github.com/passepartoutvpn/wireguard-apple.git
synced 2024-12-29 04:52:35 +00:00
e2384e143c
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
26 lines
936 B
Swift
26 lines
936 B
Swift
// SPDX-License-Identifier: MIT
|
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
|
|
|
import NetworkExtension
|
|
|
|
class ErrorNotifier {
|
|
let activationAttemptId: String?
|
|
|
|
init(activationAttemptId: String?) {
|
|
self.activationAttemptId = activationAttemptId
|
|
ErrorNotifier.removeLastErrorFile()
|
|
}
|
|
|
|
func notify(_ error: PacketTunnelProviderError) {
|
|
guard let activationAttemptId = activationAttemptId, let lastErrorFilePath = FileManager.networkExtensionLastErrorFileURL?.path else { return }
|
|
let errorMessageData = "\(activationAttemptId)\n\(error)".data(using: .utf8)
|
|
FileManager.default.createFile(atPath: lastErrorFilePath, contents: errorMessageData, attributes: nil)
|
|
}
|
|
|
|
static func removeLastErrorFile() {
|
|
if let lastErrorFileURL = FileManager.networkExtensionLastErrorFileURL {
|
|
_ = FileManager.deleteFile(at: lastErrorFileURL)
|
|
}
|
|
}
|
|
}
|