3

I'm trying to handle Alamofire errors globally, similar to this: AFNetworking: Handle error globally and repeat request

One use case would be to detect a 400 status code error (unauthorized / expired API token) and present the login page. Is there a way to hook on something in the Alamofire core or should I create my own error handler and always call validate().response() manually each time?

Thanks

Community
  • 1
  • 1
allaire
  • 5,995
  • 3
  • 41
  • 56

1 Answers1

3

At the moment you will have to handle that logic in your own custom response implementation. We (the Alamofire TC) are currently working on ways that we can make this process easier, but it's very difficult to get right without complicating the rest of the APIs. We're still a ways off yet.

With that said, I built an OAuth 2.0 system that handles this process in a different non-open-source library. It is possible, it's just difficult to do. You will need to hook into the response closure for all requests that could 401. See my answer here for a full breakdown of how to do this.

Hopefully that helps shed some light. Cheers

Community
  • 1
  • 1
cnoon
  • 16,575
  • 7
  • 58
  • 66
  • Nope, not yet. This is certainly something we'd love to add as a component library to Alamofire core, but it's not high on our priority list at the moment. – cnoon Nov 03 '15 at 15:34