Update:
I extend Http class, when I deleteDocument()
I want handle error then getTicket()
then retry ma request deleteDocument()
with new this.TICKET
:
@Injectable()
export class HttpService extends Http {
public SERVER_URL: string = 'http://10.0.0.183:8080/alfresco/s/'
public TICKET: string = ''
constructor(backend: ConnectionBackend, defaultOptions: RequestOptions) {
super(backend, defaultOptions);
}
post(url: string, body: any, options?: RequestOptionsArgs): Observable<Response> {
return this.intercept(super.post(url,body, options));
}
intercept(observable: Observable<Response>): Observable<Response> {
return observable.catch(initialError => {
if (initialError.status === 401) {
return this.getTicket()
.do(res => {
// HERE I WANT RETRY MY FIRST REQUEST
this.TICKET = res.json().data.ticket
})
} else {
return Observable.throw(initialError);
}
})
}
getTicket() {
return this.post(this.SERVER_URL + 'api/login', JSON.stringify({username: 'admin', password: 'admin'}))
}
deleteDocument(idFile: number) {
return this.post(this.SERVER_URL + 'dms/file/delfile?idfile=' + idFile + '&alf_ticket=' + this.TICKET, {}).map((data: Response) => data.json())
}
}
After receive my new ticket, I want retry my first request with new url. Thanks