Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404 errors from a resource don't clear as expected from a resource("static url").load() #300

Open
tjmorgan0 opened this issue Dec 17, 2019 · 0 comments

Comments

@tjmorgan0
Copy link

  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.

404 Clearing Log.docx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant