# RxJS finalize operator to execute logic on Observable termination

DevFeed: [RxJS finalize operator to execute logic on Observable termination](<https://devfeed.tech/articles/rxjs-finalize-operator-to-execute-logic-on-observable-termination-21343.md>)

Original publisher: [Read original article](<https://juri.dev/blog/2019/04/rxjs-finalize-operator/>)

Published: 2019-03-04T00:00:00Z

Content type: article

Language: en

Sources: [Juri Strumpflohner](<https://devfeed.tech/sources/juri-strumpflohner.md>)

Topics: [switchMap](<https://devfeed.tech/topics/switchmap.md>), [api server](<https://devfeed.tech/topics/api-server.md>), [User interface design](<https://devfeed.tech/topics/ui-design.md>), [Exception](<https://devfeed.tech/topics/exception.md>)

Tags: [angular](<https://devfeed.tech/tags/angular.md>), [beginner](<https://devfeed.tech/tags/beginner.md>), [observable](<https://devfeed.tech/tags/observable.md>), [operator](<https://devfeed.tech/tags/operator.md>), [rxjs](<https://devfeed.tech/tags/rxjs.md>)

## AI overview

The RxJS `finalize` operator runs cleanup logic when an Observable terminates, including on completion, error, or unsubscription. In the Angular HTTP example, it can re-enable a form button after a request whether the request succeeds or fails, avoiding duplicated success and error handling. The excerpt contrasts this with a success-only callback, which does not run when the Observable errors. Angular HTTP Observables complete when the request finishes, but custom Observables may behave differently, so the example's cleanup timing may not apply to them.

## Source excerpt

Lorem ipsum dolor sit amet