Upstash Documentation

Overview

2 min read

When you define a workflow endpoint, you can attach a failure function to the workflow that allows you to execute custom logic when a workflow run fails after exhausting all retry attempts.

This feature ensures that you can perform cleanup operations, logging, alerting, or any other custom error handling logic before the failed workflow run is moved to the Dead Letter Queue (DLQ).

Failure function is executed automatically when worklow run fails

The failure function automatically receives the workflow run context and the reason for the failure, so you can decide how to handle it.

You cannot create new workflow steps inside the failureFunction using context. The context provided here is only meant to expose workflow run properties (like URL, payload, and headers). Think of the failure function as an individual context.run step. It executes once with the provided context but cannot define further steps.

Info

If you use a custom authorization method to secure your workflow endpoint, add authorization to the failureFunction too. Otherwise, anyone could invoke your failure function with a request.

Read more here: securing your workflow endpoint.

Parameters#

The failureFunction receives an object with the following parameters:

contextobject#

The workflow context object containing:

Show properties
workflowRunIdstring#

The ID of the failed workflow run

urlstring#

The publicly accessible workflow endpoint URL

requestPayloadstring#

The original request payload that triggered the workflow

headersstring#

The original request headers

envstring#

Environment variables

failStatusnumber#

The HTTP status code returned by the failed workflow step.

failResponsenumber#

The response body returned by the failed workflow step.

failHeadersnumber#

The response headers returned by the failed workflow step.