Skip to content

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

@tjmorgan0

Description

@tjmorgan0
  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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions