Open Discountrobot opened 8 years ago
Could you please give a small example (or simply extend the one above), how would you use the promise if requestInterceptor has support for that?
Hello +1 to feature
Async interceptor could be important for OAuth process, which can has temporary token, needed to update before sending request
Could you also pass Response to responseInterceptor instead of Observable
Here is small example of async interceptor.
@Injectable()
@BaseUrl('https://api.someplace.com')
@DefaultHeaders({
'Accept': 'application/json',
'Content-Type': 'application/json'
})
export class SomeRESTClient extends RESTClient {
constructor(
@Inject(Http) http: Http
@Inject(AuthService) private auth: AuthService
) {
super(http)
this.setup()
}
protected requestInterceptor(req: Request): Promise<void> {
return this.auth
.token(token => {
req.headers.append('Autorization', `Bearer ${token}`)
})
}
protected responseInterceptor(res: Response): Promise<void> {
// do some stuff with raw response
}
}
The following code snippet will introduce a race condition, should one try to call SomeRESTClient before the _session has been populated, by the
createSession
request.We should add the possibility to have the requestInterceptor return a promise or similar.