I have HttpService and i want to make some refreshTokenInterceptor, but actually i have a problem with adding then/catch chain from handle method which is implemented by my interceptors.
class HttpService {
constructor(private interceptors: Interceptor[]) {
}
get() {
this.makeRequest()
}
post() {
this.makeRequest();
}
//other http methods;
makeRequest(patch, body) {
const request = { ...someData }
return this.interceptors.map(interceptor => intercepor.handle(request))
.then(modifiedReq => fetch(patch, modifiedBody))
.then(res => res.json())
}
}
ExampleInterceptor() {
handle (req) {
Promise.resolve(req)
.then(req.headers.authentication = 'Auth Token')
.catch(req => { refreshToken and retry request } )
}
}
Do you have any idea how to make chain with then/catch blocks from handle methods ?
Actually i want to have something like angular interceptor with refresh token mechanism, cuz i didn't find better method to auto token refreshing at 401 status. Maybe you have better solution how to intercept these requests in your abstract layer like HttpService i made.