Giter Club home page Giter Club logo

Comments (9)

mateuszbuda avatar mateuszbuda commented on May 18, 2024

Solution found: #6
Just needed to append InterceptingProtocol to protocol classes and not assigning new array like suggested in Usage

configuration.protocolClasses?.insert(InterceptingProtocol.self, atIndex: 0)

from responsedetective.

akashivskyy avatar akashivskyy commented on May 18, 2024

Thanks for noticing! 🍷

from responsedetective.

AnthonyMDev avatar AnthonyMDev commented on May 18, 2024

I'm having this problem while using the new suggested way of adding the protocol class with Alamofire.

from responsedetective.

AnthonyMDev avatar AnthonyMDev commented on May 18, 2024

I fixed this by using append rather than insert: atIndex:

Edit: Scratch that. This doesn't fix it. This allows the requests to work, but stops intercepting the requests.

from responsedetective.

mateuszbuda avatar mateuszbuda commented on May 18, 2024

Are you using anything else that do something with protocolClasses?

from responsedetective.

AnthonyMDev avatar AnthonyMDev commented on May 18, 2024

Here is the code that is setting up my configuration:

  let networkManager: Manager = {
    let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
    configuration.HTTPAdditionalHeaders = Manager.defaultHTTPHeaders

    configuration.protocolClasses = map(configuration.protocolClasses, { (var protocolClasses) in
      protocolClasses.insert(InterceptingProtocol.self, atIndex: 0)
      return protocolClasses
    }) ?? [InterceptingProtocol.self]

    return Manager(configuration: configuration, serverTrustPolicyManager: nil)
  }()

The configuration's protocolClasses array contains:

ResponseDetective.InterceptingProtocol,
_NSURLHTTPProtocol,
_NSURLDataProtocol,
_NSURLFTPProtocol,
_NSURLFileProtocol,
NSAboutURLProtocol

I'm going to continue attempting to debug this this morning, but I'm pretty lost at the moment.
It may be worth noting that I'm making HTTPS requests. I know there were issues in the past with that.

I'm also using the commit tagged for version 0.2

from responsedetective.

AnthonyMDev avatar AnthonyMDev commented on May 18, 2024

It seems that stopLoading is being called, which is canceling the request. But when I check out the response in the debugger, I see that the response from the server is there. I just also have an error NSURLErrorDomain code=-999 "canceled"
Because there is an error, my validation is failing.

ResponseDetective is also never logging the responses.

from responsedetective.

akashivskyy avatar akashivskyy commented on May 18, 2024

@AnthonyMDev I will investigate that. Could you provide me with a sample project?

from responsedetective.

akashivskyy avatar akashivskyy commented on May 18, 2024

Hi everyone, I came back to this issue recently and found out that cancellation happens because of Alamofire.Manager.deinit which invalidates the session, which triggers a chain reaction of cancelling all requests.

The following code:

let manager = Alamofire.Manager()
manager.request(.GET, "https://httpbin.org/get").response { _, _, _, error in
    print(error)
}

will always fail with NSURLErrorCancelled code, even with ResponseDetective disabled, because manager is deallocated before the request even starts loading.

In order for Manager to complete the tasks successfully, its instance needs to be retained (e.g. in a private property). This also makes ResponseDetective work again.

I'm closing this issue as it has been tested with retained Alamofire.Manager in the upcoming 0.4 release.

from responsedetective.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.