|
|
@ -97,20 +97,23 @@ internal enum OnionRequestAPI {
|
|
|
|
var json: JSON? = nil
|
|
|
|
var json: JSON? = nil
|
|
|
|
if let j = try? JSONSerialization.jsonObject(with: data, options: []) as? JSON {
|
|
|
|
if let j = try? JSONSerialization.jsonObject(with: data, options: []) as? JSON {
|
|
|
|
json = j
|
|
|
|
json = j
|
|
|
|
} else if let message = String(data: data, encoding: .utf8) {
|
|
|
|
} else if let result = String(data: data, encoding: .utf8) {
|
|
|
|
json = [ "message" : message ]
|
|
|
|
json = [ "result" : result ]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let jsonDescription = json?.prettifiedDescription ?? "no debugging info provided"
|
|
|
|
let jsonDescription = json?.prettifiedDescription ?? "no debugging info provided"
|
|
|
|
print("[Loki] [Onion Request API] \(verb.rawValue) request to \(url) failed with status code: \(statusCode) (\(jsonDescription)).")
|
|
|
|
print("[Loki] [Onion Request API] \(verb.rawValue) request to \(url) failed with status code: \(statusCode) (\(jsonDescription)).")
|
|
|
|
return seal.reject(Error.httpRequestFailed(statusCode: statusCode, json: json))
|
|
|
|
return seal.reject(Error.httpRequestFailed(statusCode: statusCode, json: json))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
var json: JSON! = nil
|
|
|
|
let json = try JSONSerialization.jsonObject(with: data, options: [])
|
|
|
|
if let j = try? JSONSerialization.jsonObject(with: data, options: []) as? JSON {
|
|
|
|
seal.fulfill(json)
|
|
|
|
json = j
|
|
|
|
} catch (let error) {
|
|
|
|
} else if let result = String(data: data, encoding: .utf8) {
|
|
|
|
|
|
|
|
json = [ "result" : result ]
|
|
|
|
|
|
|
|
} else {
|
|
|
|
print("[Loki] [Onion Request API] Couldn't parse JSON returned by \(verb.rawValue) request to \(url).")
|
|
|
|
print("[Loki] [Onion Request API] Couldn't parse JSON returned by \(verb.rawValue) request to \(url).")
|
|
|
|
seal.reject(error)
|
|
|
|
return seal.reject(Error.invalidJSON)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
seal.fulfill(json)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
task.resume()
|
|
|
|
task.resume()
|
|
|
|
}
|
|
|
|
}
|
|
|
|