ResponseInterceptor

public protocol ResponseInterceptor

Response Interceptors are called just before a response is going to be returned back to the caller.

Examples of things you can do here:

  • Collect/Log statistics about the failure rate of responses by counting the number of errors
  • Update your session information from every response, if they have any
  • You can even force succeed or force fail your responses in Response Interceptors

You should not do too much work synchronously in your response interceptors, since your responses have to wait for the interceptors before reaching back the caller. If you have to do long running tasks here, try dispatching them instead of running them synchronously, so that at least the intercept method returns quickly.

  • This method gives you the chance to modify the network response just before it returns back to the original caller.

    Special Modifiers:

    • You can force fail or force succeed a response here using the methods .fail() or .succeed() on NetworkResponse

    Declaration

    Swift

    func intercept(response: NetworkResponse) -> NetworkResponse

    Parameters

    response

    NetworkResponse

    Return Value

    NetworkResponse