Fix: crash when parse config request fail
This commit is contained in:
parent
f161f3d4dd
commit
bdcbb93122
@ -52,8 +52,11 @@ class ApiRequest{
|
||||
req("/configs").responseData{
|
||||
res in
|
||||
guard let data = res.result.value else {return}
|
||||
let config = ClashConfig.fromData(data)
|
||||
completeHandler(config)
|
||||
if let config = ClashConfig.fromData(data) {
|
||||
completeHandler(config)
|
||||
} else {
|
||||
NSUserNotificationCenter.default.post(title: "Error", info: "Get clash config failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,10 +32,10 @@ class ClashConfig:Codable {
|
||||
case port, socketPort = "socks-port", allowLan = "allow-lan", mode, logLevel = "log-level"
|
||||
}
|
||||
|
||||
static func fromData(_ data:Data)->ClashConfig{
|
||||
static func fromData(_ data:Data)->ClashConfig?{
|
||||
let decoder = JSONDecoder()
|
||||
let model = try? decoder.decode(ClashConfig.self, from: data)
|
||||
return model!
|
||||
return model
|
||||
}
|
||||
|
||||
func copy() -> ClashConfig? {
|
||||
|
Loading…
Reference in New Issue
Block a user