Skip to content

Commit 801f5c8

Browse files
authored
workflows: clarify get throws (#18364)
1 parent 6662bf8 commit 801f5c8

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/content/docs/workflows/build/workers-api.mdx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,24 @@ Get a specific Workflow instance by ID.
194194

195195
* `id` - the ID of the Workflow instance.
196196

197-
Returns a `WorkflowInstance`.
197+
Returns a `WorkflowInstance`. Throws an exception if the instance ID does not exist.
198+
199+
```ts
200+
// Fetch an existing Workflow instance by ID:
201+
try {
202+
let instance = await env.MY_WORKFLOW.get(id)
203+
return Response.json({
204+
id: instance.id,
205+
details: await instance.status(),
206+
});
207+
} catch (e: any) {
208+
// Handle errors
209+
// .get will throw an exception if the ID doesn't exist or is invalid.
210+
const msg = `failed to get instance ${id}: ${e.message}`
211+
console.error(msg)
212+
return Response.json({error: msg}, { status: 400 })
213+
}
214+
```
198215

199216
## WorkflowInstanceCreateOptions
200217

0 commit comments

Comments
 (0)