Giter VIP home page Giter VIP logo

Comments (5)

vadymmarkov avatar vadymmarkov commented on May 25, 2024 1

@wideving You're right, I found a bug in implementation with promise not being rejected when middleware fails. It should be fixed in #112. Please test it on master branch and if it works as expected I'll make a new release.

from malibu.

wideving avatar wideving commented on May 25, 2024 1

I did a pod update with pod 'Malibu', :git => 'https://github.com/vadymmarkov/Malibu.git', :commit => 'b2afba1' to confirm that issue is solved and everything now works as expected with rejections coming through middleware. Thank you.

from malibu.

wideving avatar wideving commented on May 25, 2024

I will add an example of what I try to do

fun getAuth() {
    networking.request(.getAuth)
    .validate()
    .done { response in
      //None of these handlers gets called
    }
    .fail { error in
        
    }
    .always { result in 
      
    }
}

networking.middleware = { promise in 
  promise.reject(NetworkError(code: 999, message: "error..")
}

from malibu.

vadymmarkov avatar vadymmarkov commented on May 25, 2024

Hi @wideving! I don't think it's a problem with reject itself, there's probably something else. Do you keep a reference to your Networking instance so it's not deallocated?

from malibu.

wideving avatar wideving commented on May 25, 2024

Hello @vadymmarkov, thank you for a quick response 👍 I don't think there is a problem with deallocation since the request goes through if I resolve instead of reject. I have no problem with your library other then when i reject in middleware nothing happens. All other requests and functionality is working fine.

Here is the code for how i create an instance of networking, its stored as a reference in appdelegate. The networking object is then injected to a viewmodel and called from there

`
func createApi(unrestrictedApi: Networking,
session: Session) -> Networking {

let api = Networking<RestrictedApi>()
api.middleware = { promise in
  if !session.shouldRefreshToken {
    api.authenticate(authorizationHeader: session.authorizationToken)
    promise.resolve(Void())
    return
  }
  
  unrestrictedApi.request(.refresh(phoneNumber: session.phoneNumber))
    .validate()
    .toData()
    .then({response -> String in
      return try JSONDecoder().decode(Authorization.self, from: response).token
    })
    .done({ token in
      guard
        let decryptedToken = CipherUtility.decrypt(encryptedString: token)
      else {
        promise.reject(NetworkError.noDataInResponse)
        return
      }
      
      session.setAuthorizationToken(token: decryptedToken)
      api.authenticate(authorizationHeader: session.authorizationToken)
      promise.resolve(Void())
    })
    .fail({ error in
      let message = NetworkErrorParser.parse(error: error)
      print("error message: \(message)")
      promise.reject(NetworkError.noDataInResponse)
    })
  }

return api

}
`

UnrestrictedApi and RestrictedApi is stored like this in appdelegate
private let unrestrictedApi = Networking<UnrestrictedApi>() private lazy var restrictedApi: Networking<RestrictedApi> = { ApiGenerator().createApi(unrestrictedApi: unrestrictedApi, session: UserAccountSession()) }()

Do you spot anything weird?

from malibu.

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.