Middleware exceptions escape the generated handleRequest and bypass configureServerErrors
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- typescript, vite
Direzione di ricerca
Start by reading src/ssr/index.ts around lines 1433-1453 and compare the server-function endpoint's handling of thrown Responses. Reproduce the production /boom case, then inspect src/node-entry/index.ts and the configureServerErrors path. Done means production middleware failures follow the stated response and error-policy behavior while dev retains its current overlay behavior.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Problem
In Start mode, the generated handleRequest runs the start.middleware chain without a catch:
When a middleware throws or rejects in a production build, the exception leaves handleRequest and each host deals with it in its own way:
- Nitro (h3) logs the original error with
console.errorand answers500with{"error":true,"status":500,"unhandled":true}as JSON. The headers and cookies the chain already wrote to the response stub are lost. start.nodelogs it and answers a plain-text 500 (src/node-entry/index.ts#L154-L161).- The
examples/start-ssrserver sendse.messageback to the client (examples/start-ssr/server.js#L78-L81).
Two consequences go beyond the inconsistent response:
- The hook registered with
configureServerErrors({ onError })never sees these failures, although its docs describe it as seeing "the failure that fails a request". Apps that rely on it to keep original errors out of logs, or to forward them to an APM (asstart.instrumentin #365 suggests), lose that for middleware, API handlers mounted in middleware, andstart.setup/start.renderModefailures. - A thrown control response turns into a 500.
return redirect('/login')from a middleware works, butthrow redirect('/login')reaches h3 as a non-Errorrejection and becomes an unhandled 500. The server-function endpoint, served by the same handler, already treats a thrownResponseas the response.
Reproduction
With @solidjs/vite-plugin 3.0.0-next.46, @solidjs/web 2.0.0-rc.11 and Nitro 3 beta:
// the module passed to start.middleware
export default async function middleware(request: Request, next: () => Promise<Response>) {
if (new URL(request.url).pathname === '/boom') throw new Error('token=abc123')
return next()
}
Build for production, serve it and request /boom: the response is Nitro's JSON 500, the server log shows Error: token=abc123 with its stack, and a hook registered with configureServerErrors is not called.
Expected
In production builds, the generated handler contains request failures the way the server-function endpoint does:
- a thrown
Response(exceptResponse.error()) or response envelope becomes the response; - anything else goes through the configured server error policy and yields a generic 500 that still carries the stub's headers and cookies;
- dev keeps the current behavior, so the Vite overlay still shows the original error.
Notes
- There is no public API today to run a value through the configured policy outside a render, so the handler would have to call the hook registered under the
configureServerErrorssymbol. A public entry point in@solidjs/webfor request failures, with its ownkindinServerErrorSite, would remove that coupling. - A later step could render the app's error boundary when the chain fails before the page render, so a failed navigation gets an HTML error page instead of an empty 500. Apps can do that in userland today, but it depends on the single-render rule and on excluding the server-function endpoint.
- Related: #328, since a deploy adapter would benefit from a handler that does not reject for application failures.
I'll follow up with a PR for the containment part.
- Lingua principale
- TypeScript
- Stelle
- 520
- Fork
- 70
- Merge medio
- 21h 42m
- PR unite (30g)
- 36
Preparare l'ambiente
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di solidjs/solid-vite-plugin
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
solidjs/solid-vite-plugin#205 · 1 commento · 2 reazioni ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
solidjs/solid-vite-plugin#388 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
solidjs/solid-vite-plugin#387 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
solidjs/solid-vite-plugin#381 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 76/100
solidjs/solid-vite-plugin#375 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di solidjs/solid-vite-plugin
Issue simili
-
area/frontend good first issue kind/cooldown
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
voidzero-dev/oxc-angular-compiler#511 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
langchain-ai/deepagentsjs#898 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
anomalyco/models.dev#8509 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
bug documentation P2 UI/UX
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno