mirror of
https://github.com/cranci1/Sora.git
synced 2026-04-05 00:59:55 +00:00
test logger that should work now
This commit is contained in:
parent
30a194f5b8
commit
01f90882f9
1 changed files with 11 additions and 4 deletions
|
|
@ -16,6 +16,13 @@ class JSController: ObservableObject {
|
|||
}
|
||||
|
||||
private func setupContext() {
|
||||
let consoleObject = JSValue(newObjectIn: context)
|
||||
let consoleLogFunction: @convention(block) (String) -> Void = { message in
|
||||
Logger.shared.log(message, type: "Debug")
|
||||
}
|
||||
consoleObject?.setObject(consoleLogFunction, forKeyedSubscript: "log" as NSString)
|
||||
context.setObject(consoleObject, forKeyedSubscript: "console" as NSString)
|
||||
|
||||
let logFunction: @convention(block) (String) -> Void = { message in
|
||||
Logger.shared.log("JavaScript log: \(message)", type: "Debug")
|
||||
}
|
||||
|
|
@ -23,7 +30,7 @@ class JSController: ObservableObject {
|
|||
|
||||
let fetchNativeFunction: @convention(block) (String, [String: String]?, JSValue, JSValue) -> Void = { urlString, headers, resolve, reject in
|
||||
guard let url = URL(string: urlString) else {
|
||||
Logger.shared.log("Invalid URL",type: "Error")
|
||||
Logger.shared.log("Invalid URL", type: "Error")
|
||||
reject.call(withArguments: ["Invalid URL"])
|
||||
return
|
||||
}
|
||||
|
|
@ -35,19 +42,19 @@ class JSController: ObservableObject {
|
|||
}
|
||||
let task = URLSession.custom.dataTask(with: request) { data, _, error in
|
||||
if let error = error {
|
||||
Logger.shared.log("Network error in fetchNativeFunction: \(error.localizedDescription)",type: "Error")
|
||||
Logger.shared.log("Network error in fetchNativeFunction: \(error.localizedDescription)", type: "Error")
|
||||
reject.call(withArguments: [error.localizedDescription])
|
||||
return
|
||||
}
|
||||
guard let data = data else {
|
||||
Logger.shared.log("No data in response",type: "Error")
|
||||
Logger.shared.log("No data in response", type: "Error")
|
||||
reject.call(withArguments: ["No data"])
|
||||
return
|
||||
}
|
||||
if let text = String(data: data, encoding: .utf8) {
|
||||
resolve.call(withArguments: [text])
|
||||
} else {
|
||||
Logger.shared.log("Unable to decode data to text",type: "Error")
|
||||
Logger.shared.log("Unable to decode data to text", type: "Error")
|
||||
reject.call(withArguments: ["Unable to decode data"])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue