Hi there,
I'm using DVR, and so far I've managed successfully to create tests when api requests return success. But now I want to test the failure of the same requests. So I'm facing a problem when using DVR to test failures (401, 404 etc)..
When run for 2nd time (first time is to record the response), instead of failure callback, success callback is called with the error response inside of it. Any idea why?
Using Alamofire.
Example code (creating and executing any request):
request.validate().responseJSON(completionHandler: {
response in
switch response.result {
case .success(let JSON):
// This is what gets called instead of failure. Response code is 401 and the JSON contains error message.
callback(true, JSON, nil)
case .failure(let error):
if let data = response.data, data.count > 0 {
let JSON = try! JSONSerialization.jsonObject(with: data, options: .allowFragments)
callback(false, JSON, error as NSError?)
} else {
callback(false, nil, error as NSError?)
}
}
}).resume()
Hi there, I'm using DVR, and so far I've managed successfully to create tests when api requests return success. But now I want to test the failure of the same requests. So I'm facing a problem when using DVR to test failures (401, 404 etc)..
When run for 2nd time (first time is to record the response), instead of failure callback, success callback is called with the error response inside of it. Any idea why?
Using Alamofire. Example code (creating and executing any request):