Coder Social home page Coder Social logo

Comments (4)

Optimiza avatar Optimiza commented on September 23, 2024

Update:

I was using AFMotion::SessionClient, changed it to AFMotion::Client and result.object is working fine.

Maybe is the way it works.

from afmotion.

sajoku avatar sajoku commented on September 23, 2024

@Optimiza Since AFMotion is just a 'thin' wrapper around AFNetworking it handles responses the same way. I think this is due to the way AFNetworking SessionManager handles responses with a statuscode other than 200.

https://github.com/AFNetworking/AFNetworking/issues/1397

from afmotion.

Optimiza avatar Optimiza commented on September 23, 2024

Thanks @sajoku it makes sense.

Anyway I think im doing right sending error information detailed with 4xx.

Will read it and try to find where is that information now.

from afmotion.

wprater avatar wprater commented on September 23, 2024

I got around this by creating a subclass of the AFJSONResponseSerializer and overrode the - (id)responseObjectForResponse:data:error: method. This way I can set the userInfo dictionary to whatever I need.

ex:

class MyJSONResponseSerializer < AFJSONResponseSerializer
  def responseObjectForResponse(response, data: data, error: error)
    response_object = super

    unless error[0].nil?
      err = error[0]

      user_info = err.userInfo.dup
      user_info[NSLocalizedDescriptionKey] = response_object[:message]
      user_info[NSLocalizedFailureReasonErrorKey] = response_object[:code]

      error[0] = NSError.errorWithDomain(err.domain, code: err.code, userInfo: user_info)
    end

    response_object
  end
end

AFMotion::SessionClient.build_shared(MyApp.api_endpoint) do
  session_configuration :default
  header 'Accept', 'application/json'

  request_serializer :json
  response_serializer FlareJSONResponseSerializer
end

from afmotion.

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.