You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My app needs to monitor the network connection to an API. After enough errors accumulate, It stops making normal requests and lazily pings the API with a static URL as follows:
let userRequest = VAPI.sharedInstance.resource("").load(). // Base url is a health check for the api.
When an adequate number of successful pings has occurred, the app goes back to normal operation. During testing I can inject errors into the API response and clear them as needed. For every error except 404, the system works as expected. With 404, the ping keeps getting 404 responses from the load() even after the network response has gone back to a normal 200.
As the error clears the load() returns 1 good response and then resumes returning 404. Using URLSession I get a 200 for the success. With Alamofire, the success is a 304. A parallel direct URLSession request as follows:
// Test code
let url = URL.init(string: VAPI.VAPIBaseURL)
let dataTask = self.defaultSession.dataTask(with: url!) { [weak self] data, response, error in
// 5
if error != nil {
print(error?.localizedDescription)
} else if let data = data,
let response = response as? HTTPURLResponse {
print("URLSession Response =====> ", response.statusCode)
}
}
dataTask.resume()
Behaves as expected. I've attached a log file of the divergent responses.
When an adequate number of successful pings has occurred, the app goes back to normal operation. During testing I can inject errors into the API response and clear them as needed. For every error except 404, the system works as expected. With 404, the ping keeps getting 404 responses from the load() even after the network response has gone back to a normal 200.
As the error clears the load() returns 1 good response and then resumes returning 404. Using URLSession I get a 200 for the success. With Alamofire, the success is a 304. A parallel direct URLSession request as follows:
// Test code
let url = URL.init(string: VAPI.VAPIBaseURL)
let dataTask = self.defaultSession.dataTask(with: url!) { [weak self] data, response, error in
// 5
if error != nil {
print(error?.localizedDescription)
} else if let data = data,
let response = response as? HTTPURLResponse {
print("URLSession Response =====> ", response.statusCode)
}
}
Behaves as expected. I've attached a log file of the divergent responses.
404 Clearing Log.docx
The text was updated successfully, but these errors were encountered: