Timeout
This commit is contained in:
parent
f6c9cc5ef3
commit
620d0ab88d
2 changed files with 13 additions and 4 deletions
|
|
@ -23,7 +23,7 @@ class ApiService {
|
|||
Log.d(tag, "Polling single message from \(url) with user \(user?.username ?? "anonymous")")
|
||||
|
||||
let request = newRequest(url: url, user: user)
|
||||
URLSession.shared.dataTask(with: request) { (data, response, error) in
|
||||
newSession(timeout: 30).dataTask(with: request) { (data, response, error) in
|
||||
if let error = error {
|
||||
completionHandler(nil, error)
|
||||
return
|
||||
|
|
@ -55,7 +55,7 @@ class ApiService {
|
|||
request.setValue(String(priority), forHTTPHeaderField: "Priority")
|
||||
request.setValue(tags.joined(separator: ","), forHTTPHeaderField: "Tags")
|
||||
request.httpBody = message.data(using: String.Encoding.utf8)
|
||||
URLSession.shared.dataTask(with: request) { (data, response, error) in
|
||||
newSession(timeout: 10).dataTask(with: request) { (data, response, error) in
|
||||
guard error == nil else {
|
||||
Log.e(self.tag, "Error publishing message", error!)
|
||||
return
|
||||
|
|
@ -68,7 +68,7 @@ class ApiService {
|
|||
guard let url = URL(string: topicAuthUrl(baseUrl: baseUrl, topic: topic)) else { return }
|
||||
let request = newRequest(url: url, user: user)
|
||||
Log.d(tag, "Checking auth for \(url) with user \(user?.username ?? "anonymous")")
|
||||
URLSession.shared.dataTask(with: request) { (data, response, error) in
|
||||
newSession(timeout: 10).dataTask(with: request) { (data, response, error) in
|
||||
if let error = error {
|
||||
Log.e(self.tag, "Error checking auth: \(error)")
|
||||
completionHandler(.Error(error.localizedDescription))
|
||||
|
|
@ -98,7 +98,7 @@ class ApiService {
|
|||
private func fetchJsonData<T: Decodable>(urlString: String, user: BasicUser?, completionHandler: @escaping ([T]?, Error?) -> ()) {
|
||||
guard let url = URL(string: urlString) else { return }
|
||||
let request = newRequest(url: url, user: user)
|
||||
URLSession.shared.dataTask(with: request) { (data, response, error) in
|
||||
newSession(timeout: 30).dataTask(with: request) { (data, response, error) in
|
||||
if let error = error {
|
||||
Log.e(self.tag, "Error fetching data", error)
|
||||
completionHandler(nil, error)
|
||||
|
|
@ -126,6 +126,13 @@ class ApiService {
|
|||
}
|
||||
return request
|
||||
}
|
||||
|
||||
private func newSession(timeout: TimeInterval) -> URLSession {
|
||||
let sessionConfig = URLSessionConfiguration.default
|
||||
sessionConfig.timeoutIntervalForRequest = timeout
|
||||
sessionConfig.timeoutIntervalForResource = timeout
|
||||
return URLSession(configuration: sessionConfig)
|
||||
}
|
||||
}
|
||||
|
||||
struct BasicUser {
|
||||
|
|
|
|||
|
|
@ -123,6 +123,8 @@ struct UsersView: View {
|
|||
return false
|
||||
} else if username.isEmpty || password.isEmpty {
|
||||
return false
|
||||
} else if store.getUser(baseUrl: baseUrl) != nil {
|
||||
return false
|
||||
}
|
||||
} else { // Existing user
|
||||
if username.isEmpty {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue