2018-11-09 11:23:52 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-01-02 00:56:33 +00:00
|
|
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
2018-11-09 11:23:52 +00:00
|
|
|
|
|
|
|
import NetworkExtension
|
|
|
|
|
|
|
|
class ErrorNotifier {
|
2018-12-13 20:54:53 +00:00
|
|
|
let activationAttemptId: String?
|
|
|
|
|
2018-12-22 02:41:54 +00:00
|
|
|
init(activationAttemptId: String?) {
|
2018-12-13 20:54:53 +00:00
|
|
|
self.activationAttemptId = activationAttemptId
|
|
|
|
ErrorNotifier.removeLastErrorFile()
|
|
|
|
}
|
|
|
|
|
|
|
|
func notify(_ error: PacketTunnelProviderError) {
|
2018-12-22 02:41:54 +00:00
|
|
|
guard let activationAttemptId = activationAttemptId, let lastErrorFilePath = FileManager.networkExtensionLastErrorFileURL?.path else { return }
|
|
|
|
let errorMessageData = "\(activationAttemptId)\n\(error)".data(using: .utf8)
|
2018-12-21 17:50:32 +00:00
|
|
|
FileManager.default.createFile(atPath: lastErrorFilePath, contents: errorMessageData, attributes: nil)
|
2018-12-13 20:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static func removeLastErrorFile() {
|
|
|
|
if let lastErrorFileURL = FileManager.networkExtensionLastErrorFileURL {
|
|
|
|
_ = FileManager.deleteFile(at: lastErrorFileURL)
|
|
|
|
}
|
2018-11-09 11:23:52 +00:00
|
|
|
}
|
|
|
|
}
|