Skip to main content
Skip to main content

permanentFailure

Creates a StepResponse that indicates that the step has failed and the retry mechanism should not kick in anymore.

Example

import { Product } from "@medusajs/medusa"
import {
createStep,
StepResponse,
createWorkflow
} from "@medusajs/workflows-sdk"

interface CreateProductInput {
title: string
}

export const createProductStep = createStep(
"createProductStep",
async function (
input: CreateProductInput,
context
) {
const productService = context.container.resolve(
"productService"
)

try {
const product = await productService.create(input)
return new StepResponse({
product
}, {
product_id: product.id
})
} catch (e) {
return StepResponse.permanentFailure(`Couldn't create the product: ${e}`)
}
}
)

interface WorkflowInput {
title: string
}

const myWorkflow = createWorkflow<
WorkflowInput,
Product
>("my-workflow", (input) => {
// Everything here will be executed and resolved later
// during the execution. Including the data access.

const product = createProductStep(input)
}
)

myWorkflow()
.run({
input: {
title: "Shirt"
}
})
.then(({ errors, result }) => {
if (errors.length) {
errors.forEach((err) => {
if (typeof err.error === "object" && "message" in err.error) {
console.error(err.error.message)
} else {
console.error(err.error)
}
})
}
console.log(result)
})

Parameters

messagestringRequired
An optional message to be logged.

Default: "Permanent failure"

Returns

neverneverRequired
Creates a StepResponse that indicates that the step has failed and the retry mechanism should not kick in anymore.
Was this section helpful?