Skip to content

Instantly share code, notes, and snippets.

@dinorahtovar
Created July 19, 2018 18:12
Show Gist options
  • Save dinorahtovar/a6da7799defd2f884b7c7a3aaab73d28 to your computer and use it in GitHub Desktop.
Save dinorahtovar/a6da7799defd2f884b7c7a3aaab73d28 to your computer and use it in GitHub Desktop.
/**
* Created by Dinorah Tovar on 04/04/18.
* Secondary helper interceptor to skip interceptor headers over Data Module
*/
class SupportInterceptor: Interceptor, Authenticator {
/**
* Interceptor class for setting of the headers for every request
*/
override fun intercept(chain: Interceptor.Chain): Response {
var request = chain.request()
request = request?.newBuilder()
?.addHeader("Content-Type", "application/json")
?.addHeader("Accept", "application/json")
?.build()
return chain.proceed(request)
}
/**
* Authenticator for when the authToken need to be refresh and updated
* everytime we get a 401 error code
*/
@Throws(IOException::class)
override fun authenticate (route: Route?, response: Response?): Request? {
var requestAvailable: Request? = null
try {
requestAvailable = response?.request()?.newBuilder()
?.addHeader("AUTH_TOKEN", "UUID.randomUUID().toString()")
?.build()
return requestAvailable
} catch (ex: Exception) { }
return requestAvailable
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment