Access Workflow Errors

In this chapter, you’ll learn how to access errors that occur during a workflow’s execution.

How to Access Workflow Errors?#

By default, when an error occurs in a workflow, it throws that error, and the execution stops.

You can configure the workflow to return the errors instead so that you can access and handle them differently.

For example:

src/api/workflows/route.ts
5import myWorkflow from "../../../workflows/hello-world"6
7export async function GET(8  req: MedusaRequest,9  res: MedusaResponse10) {11  const { result, errors } = await myWorkflow(req.scope)12    .run({13	    // ...14      throwOnError: false,15    })16
17  if (errors.length) {18    return res.send({19      errors: errors.map((error) => error.error),20    })21  }22
23  res.send(result)24}

The object passed to the run method accepts a throwOnError property. When disabled, the errors are returned in the errors property of run's output.

The value of errors is an array of error objects. Each object has an error property, whose value is the name or text of the thrown error.

Was this chapter helpful?
Edit this page
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break