diff --git a/src/content/docs/workflows/build/workers-api.mdx b/src/content/docs/workflows/build/workers-api.mdx index 34d98d76b3c25ff..1b48851d49bbb6b 100644 --- a/src/content/docs/workflows/build/workers-api.mdx +++ b/src/content/docs/workflows/build/workers-api.mdx @@ -194,7 +194,24 @@ Get a specific Workflow instance by ID. * `id` - the ID of the Workflow instance. -Returns a `WorkflowInstance`. +Returns a `WorkflowInstance`. Throws an exception if the instance ID does not exist. + +```ts +// Fetch an existing Workflow instance by ID: +try { + let instance = await env.MY_WORKFLOW.get(id) + return Response.json({ + id: instance.id, + details: await instance.status(), + }); +} catch (e: any) { + // Handle errors + // .get will throw an exception if the ID doesn't exist or is invalid. + const msg = `failed to get instance ${id}: ${e.message}` + console.error(msg) + return Response.json({error: msg}, { status: 400 }) +} +``` ## WorkflowInstanceCreateOptions