#if ENABLE_JSON_LOG
-class JSONViewCommand: JSONCommand {
+final class JSONViewCommand: JSONCommand {
+
let jsonTree: [JSONNode]?
let parameterList: [Any]
let recieveDate: Date?
let command: JSONCommand
init(apiResponse: APIResponse, command: JSONCommand) {
+
self.recieveDate = Date()
- self.parameterList = apiResponse.argumentArray
+ self.parameterList = apiResponse
+ .parameter
+ .map { ["key": $0, "value": $1] }
self.jsonTree = JSONNode
- .nodeWithJSON(apiResponse.json as AnyObject?)
+ .nodeWithJSON(apiResponse.json)
.map { [$0] }
self.command = command
+
super.init(apiResponse: apiResponse)
}
required init(apiResponse: APIResponse) {
+
fatalError("use init(apiResponse:command:)")
}
override func execute() {
- command.execute()
- guard let _ = jsonTree else { return print("jsonTree is nil.") }
- guard let _ = recieveDate else { return print("recieveDate is nil.") }
+ do {
+
+ try command.execute()
+
+ } catch {
+
+ print("JSONTracker Cought Exception -> \(error)")
+ }
+
+ guard let _ = jsonTree else {
+
+ Logger.shared.log("jsonTree is nil.")
+
+ return
+ }
+ guard let _ = recieveDate else {
+
+ Logger.shared.log("recieveDate is nil.")
+
+ return
+ }
DispatchQueue.main.async {
- guard let appDelegate = NSApplication.shared().delegate as? AppDelegate
- else { return print("Can not get AppDelegate") }
- let commands: [String:Any] = [
- "api": self.api,
+
+ let commands: [String: Any] = [
+ "api": self.api.debugDescription,
"argument": self.parameterList,
"json": self.jsonTree ?? [],
"recieveDate": self.recieveDate ?? Date(),
"date": Date()
]
- appDelegate.jsonViewWindowController?.setCommand(commands as NSDictionary)
+ AppDelegate.shared.jsonViewWindowController?.setCommand(commands)
}
}
}