From f9c162f25bef7c582d22330d35eec9b8309644cd Mon Sep 17 00:00:00 2001 From: SandObserver <260779319+SandObserver@users.noreply.github.com> Date: Fri, 2 Oct 2026 16:21:12 -0400 Subject: [PATCH] Show error-status checks in the widget data example The template reports a missing URL, error statuses and a reply without items through ctx.fail. The example matches it, and the sentence claiming the template returns { error } is replaced. --- src/content/docs/docs/create-a-widget/index.mdx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/content/docs/docs/create-a-widget/index.mdx b/src/content/docs/docs/create-a-widget/index.mdx index d055cb5..b2c88de 100644 --- a/src/content/docs/docs/create-a-widget/index.mdx +++ b/src/content/docs/docs/create-a-widget/index.mdx @@ -49,15 +49,18 @@ module.exports = async function (ctx) { headers: apiKey ? { 'X-Api-Key': apiKey } : {}, timeout: 8000, }); + if (r.status === 401 || r.status === 403) ctx.fail('Auth failed (check API key)', { kind: ctx.KIND.AUTH }); + if (r.status >= 400) ctx.fail('HTTP ' + r.status); + if (!r.data || !Array.isArray(r.data.items)) ctx.fail('Reply has no items'); return { - items: (r.data.items || []).slice(0, 10).map(i => ({ name: i.name })), - total: r.data.total ?? 0, + items: r.data.items.slice(0, 10).map(i => ({ name: i.name })), + total: r.data.total ?? r.data.items.length, }; }; ``` -The return value is served at `/api/widget-data/`. The template returns `{ error }` when the URL is missing. Use `ctx.fail` as shown, so the widget shows its failure state. See [Data](/docs/create-a-widget/data/). +The return value is served at `/api/widget-data/`. Report every failure through `ctx.fail`, as the template does, so the widget shows its failure state. See [Data](/docs/create-a-widget/data/). ## 4. Page