# How to handle cancellation and termination gracefully

**URL:** <https://community.temporal.io/t/how-to-handle-cancellation-and-termination-gracefully/17193>\
**Category:** Community Support\
**Tags:** typescript-sdk\
**Created:** [April 21, 2025, 12:15pm UTC](https://community.temporal.io/t/how-to-handle-cancellation-and-termination-gracefully/17193 "2025-04-21T12:15:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kishore\_kumar](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/kishore_kumar/32/4015_2.png) [@kishore\_kumar](https://community.temporal.io/u/kishore_kumar)\
**Post date:** [April 21, 2025, 12:15pm UTC](https://community.temporal.io/t/how-to-handle-cancellation-and-termination-gracefully/17193/1 "2025-04-21T12:15:02Z")

</div>

When ever a cancellation or termination of a workflow is done from the ui or client. How can we gracefully handle it using typescript sdk?

I need to execute a db operation in the workflow before workflow is terminated or cancelled.

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [April 21, 2025, 1:12pm UTC](https://community.temporal.io/t/how-to-handle-cancellation-and-termination-gracefully/17193/2 "2025-04-21T13:12:37Z")

</div>

For workflow cancelation to run activity it needs to exec in noncancellable scope: [Class: CancellationScope | Temporal TypeScript SDK API Reference](https://typescript.temporal.io/api/classes/workflow.CancellationScope)

Your worker cannot react to workflow termination so preferred not to terminate executions in most if not all cases if possible.
