Skip to content
cccskills
FreePublished on GitHub

hono-subapp-undefined-response-1101

Fix Cloudflare Workers Error 1101 "Worker threw exception" caused by Hono sub-app route handlers returning undefined instead of a Response. Use when: (1) Error 1101 on a specific hostname but not others sharing the same worker, (2) "the Promise did not resolve to 'Response'" in wrangler dev logs, (3) Hono sub-app route handler uses bare `return` to skip handling for non-matching hostnames or conditions. The fix is to add `next` parameter and call `return next()` instead of bare `return` in route handlers that conditionally skip.

The English summary is being prepared. Showing the original description.

Works withCloudflare
See how to install

Files included (1)

  • SKILL.md4.0 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Hono Sub-App Route Handler Returns Undefined → CF Error 1101

Problem

A Cloudflare Worker using Hono with sub-apps crashes with Error 1101 ("Worker threw exception") when a route handler in a sub-app returns undefined instead of a Response. This commonly happens when route handlers have hostname guards that use bare return to skip processing, intending to let other routes handle the request.

Context / Trigger Conditions

  • Cloudflare Workers dashboard or browser shows Error 1101: Worker threw exception
  • wrangler dev logs show: "Incorrect type for Promise: the Promise did not resolve to 'Response'"
  • Multiple hostnames route to the same worker (e.g., names.divine.video and names.admin.divine.video)
  • Hono sub-app has route handlers with conditional hostname checks that use bare return
  • The sub-app has middleware that calls next() for non-matching hostnames, but the route handlers duplicate the check and return undefined

Root Cause

In Hono, route handlers (.get(), .post(), etc.) MUST return a Response. Only middleware (registered via .use()) can call next() to pass control downstream.

However, if a route handler includes next in its parameter list (async (c, next) => {}), Hono treats it as middleware-like, allowing return next() to pass control to the next matching handler.

A bare return (which returns undefined) from a route handler causes the Cloudflare Workers runtime to throw because it expects a Response object.

Solution

Bad — returns undefined, crashes the worker:

app.get('/', async (c) => {
  if (!ALLOWED_HOSTNAMES.includes(hostname)) {
    return // undefined! → Error 1101
  }
  return c.html(page())
})

Good — accepts next parameter and calls it to pass control:

app.get('/', async (c, next) => {
  if (!ALLOWED_HOSTNAMES.includes(hostname)) {
    return next() // passes to next handler in chain
  }
  return c.html(page())
})

Key insight: Adding next to the handler signature changes Hono's treatment of the handler, allowing it to delegate to downstream routes.

Verification

  1. Run wrangler dev and curl with the non-matching hostname:
    curl -s -o /dev/null -w "%{http_code}" http://localhost:8787/ -H "Host: other.example.com"
    
  2. Should return a valid HTTP status (200, 404, etc.) instead of 500
  3. No "did not resolve to Response" errors in the terminal

Example

A worker serves both names.divine.video (public UI) and names.admin.divine.video (admin SPA). The public routes sub-app has a landing page handler that only responds for names.divine.video. When names.admin.divine.video hits this handler, it should pass through to the catch-all admin SPA handler. Using bare return crashes the worker; using return next() (with next in params) properly delegates.

Notes

  • This only applies to Hono route handlers, not middleware (.use() handlers always have next)
  • The error is invisible in Cloudflare's dashboard — you only see generic "Error 1101"
  • wrangler dev gives the real error: "the Promise did not resolve to 'Response'"
  • If your sub-app middleware already guards routes, you may not need hostname checks in individual handlers at all — but if you do, use the next pattern
  • This pattern is common in multi-tenant workers where one worker handles multiple hostnames

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Fix ArgoCD ExternalSecret deployment failing with "namespace X is not permitted in project Y". Use when: (1) ExternalSecret shows OutOfSync in ArgoCD but won't sync, (2) ArgoCD application status shows "namespace X is not permitted in project 'infrastructure'", (3) ExternalSecret targets a namespace managed by a different ArgoCD project, (4) Using apps-of-apps pattern with separate infrastructure and application projects.

The English summary is being prepared. Showing the original description.

divinevideo/divine-mobile265Updated Oct 23, 2026

Art direction for any content — reads text, PDF, Word, HTML, PPT, then proposes 2-3 creative directions with photography style, mood, and visual language. After selection, generates AI image prompts and visual briefs section-by-section. Use when the user shares content and needs visual direction, image sourcing, or creative direction for any material.

The English summary is being prepared. Showing the original description.

divinevideo/divine-mobile265Updated Oct 23, 2026

Fix "Null check operator used on a null value" errors when an object is set to null during an async await. Use when: (1) Object reference is nullified while awaiting, (2) Code accesses object with ! after await returns, (3) Cancel/dispose operations run concurrently with async operations on same object. Solution: capture local reference before await.

The English summary is being prepared. Showing the original description.

divinevideo/divine-mobile265Updated Oct 23, 2026

Add custom metadata headers (x-amz-meta-*) to AWS v4 signed requests for GCS S3-compatible API. Use when: (1) Adding custom metadata to GCS uploads via S3 API, (2) Getting signature mismatch errors after adding new headers, (3) x-amz-meta-* headers being ignored or causing 403 errors. Custom headers MUST be included in canonical headers and signed headers list.

The English summary is being prepared. Showing the original description.

divinevideo/divine-mobile265Updated Oct 23, 2026

Fix password/secret authentication failures caused by trailing newlines when creating Google Cloud secrets (or similar) with bash here-strings. Use when: (1) Password authentication fails with correct password, (2) Secret created with `<<< "value"` syntax, (3) Error like "password authentication failed" or "invalid token" despite correct value. Bash here-strings (`<<<`) add a trailing newline that corrupts secrets.

The English summary is being prepared. Showing the original description.

divinevideo/divine-mobile265Updated Oct 23, 2026

Fix silent video/media processing failures caused by URL extraction code that filters on file extensions (.mp4, .webm, .webp). Use when: (1) Media moderation, transcoding, or analysis silently skips files from Blossom or content-addressed storage servers, (2) URL extraction from Nostr event tags (imeta, r tags) drops URLs without recognized extensions, (3) CDN fallback URLs append .mp4 but the actual server uses extensionless content-addressed paths like /{sha256}. Common in Nostr video events (kind 34236) where different clients use different URL formats.

The English summary is being prepared. Showing the original description.

divinevideo/divine-mobile265Updated Oct 23, 2026

See all skills by divinevideo

Report a problem with this skill