I am using Siesta framework and trying to add decorator in order to refresh token when it expires but I am getting: 'self captured by a closure before all members were initialized'.
What could be the reason?
service.configure("**") {
$0.decorateRequests {
self.refreshTokenOnAuthFailure(request: $1) // this line complains
}
}
UPDATE
I found my problem and wanted to share it with you. The problem is related to services which were class properties:
class API: NSObject {
private let service = Service(
baseURL: myApiBaseUrl,
standardTransformers: [.text, .json]
)
override init() {
#if DEBUG
// Bare-bones logging of which network calls Siesta makes:
LogCategory.enabled = [.network]
#endif
service.configure("**") {
$0.headers["Token"] = "Bearer \(token)"
$0.headers["Content-Type"] = "application/json"
$0.headers["Accept"] = "application/json"
$0.decorateRequests {
self.refreshTokenOnAuthFailure(request: $1)
}
}
}
Instead of using a class property, I moved my service outside of the class and added a designated initializer.
init(myService:Service){
super.init()
myService.configure("**") {
$0.headers["Token"] = "Bearer \(token)"
$0.headers["Content-Type"] = "application/json"
$0.headers["Accept"] = "application/json"
$0.decorateRequests {
self.refreshTokenOnAuthFailure(request: $1)
}
}
}