Angular : how to call finally() with RXJS 6
use
throwError
instead ofObservable.throw
, see https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md#observable-classesfinally
was renamed tofinalize
and you'll use it insidepipe()
among other operators.the same with
publish()
andrefCount()
. Both are operators you'll use insidepipe()
.
According to official document, You should change your code like this to avoid compile error: (You must throw exception in catchError
method. finalize
callback method has no argument.)
import { catchError, finalize } from 'rxjs/operators';return next.handle(clonedreq).pipe( catchError(error => { console.log('error occured:', error); throw error; }), finalize(() => { console.log('finalize') }));
It is successfully compiled in Angular CLI: 7.1.4.