Hono subapp undefined response 1101

From divinevideo/divine-mobile · View interactive version

Hono subapp undefined response 1101 is an AI agent skill from the GitHub repository divinevideo/divine-mobile. 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

How to use this skill

Skill file

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

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:

```bash

curl -s -o /dev/null -w "%{http_code}" http://localhost:8787/ -H "Host: other.example.com"

```

  1. Should return a valid HTTP status (200, 404, etc.) instead of 500
  2. 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

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.