From f9c67ac9476b7ed34003bc6ef5f9b1dbbe295bb1 Mon Sep 17 00:00:00 2001 From: Matt Silverlock Date: Sat, 23 Nov 2024 07:13:30 -0500 Subject: [PATCH] workflows: clarify get throws --- .../docs/workflows/build/workers-api.mdx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/content/docs/workflows/build/workers-api.mdx b/src/content/docs/workflows/build/workers-api.mdx index 34d98d76b3c25f..1b48851d49bbb6 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