You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature?]: Could createMiddleware expose like "onError" handler for processing errors uniformly聽#1660
The issue doesn't say which errors you want to handle, so here is what SolidStart 2.x offers today. I tested each case in dev on 2.x. I have not checked 1.x, where middleware has no next(), so none of this applies there.
Where the error is thrown
How to handle it on 2.x
API routes, and any middleware that runs after yours
an h3 middleware that wraps await next() in try/catch
server functions
the serverFunctions.onError option
rendering a page
only visible as a 500 status after next(); the error itself does not reach the middleware
// src/middleware.tsimport{createMiddleware}from"@solidjs/start/middleware";exportdefaultcreateMiddleware([async(event,next)=>{try{constresponse=awaitnext();// A page that failed to render arrives here with a 500 status, but// without the error object.if(event.res.status>=500)reportFailedPage(event.url.pathname);returnresponse;}catch(error){// Errors thrown in API routes and in later middleware.reportError(error);returnnewResponse("Internal Server Error",{status: 500});}},]);
Server functions don't throw to the middleware, because their errors are sent to the caller. They have their own hook, which runs before the error is sent:
// vite.config.tssolidStart({serverFunctions: {onError: "./src/server-fn-error.ts"}});// src/server-fn-error.tsimporttype{ServerFunctionErrorHandler}from"@solidjs/start/server";constonServerFunctionError: ServerFunctionErrorHandler=thrown=>{if(throwninstanceofResponse)returnthrown;// keep redirect() and other control flowreportError(thrown);};exportdefaultonServerFunctionError;
On 2.x, the onRequest / onBeforeResponse object form of createMiddleware is deprecated in favor of h3 middleware like the one above, so a new onError key there is unlikely. The remaining gap is getting the error object when a page fails to render.
@emogua, which errors do you need to handle, and on which SolidStart version? If you need page render errors on the server, or you are on 1.x, a small example of what you're trying to report would help decide what to add.
Closing, as we don't plan to add an onError option to createMiddleware.
On 2.x, the object form of createMiddleware (onRequest / onBeforeResponse) is deprecated in favor of h3 middleware. The approaches in my previous comment cover errors from API routes, later middleware and server functions.
If you need something those don't cover, please open a new issue with the errors you want to handle, the SolidStart version, and a small example.
Activity
lxsmnsyc commentedon Oct 14, 2026
The issue doesn't say which errors you want to handle, so here is what SolidStart 2.x offers today. I tested each case in dev on 2.x. I have not checked 1.x, where middleware has no
next(), so none of this applies there.await next()intry/catchserverFunctions.onErroroption500status afternext(); the error itself does not reach the middlewareServer functions don't throw to the middleware, because their errors are sent to the caller. They have their own hook, which runs before the error is sent:
On 2.x, the
onRequest/onBeforeResponseobject form ofcreateMiddlewareis deprecated in favor of h3 middleware like the one above, so a newonErrorkey there is unlikely. The remaining gap is getting the error object when a page fails to render.@emogua, which errors do you need to handle, and on which SolidStart version? If you need page render errors on the server, or you are on 1.x, a small example of what you're trying to report would help decide what to add.
lxsmnsyc commentedon Oct 18, 2026
Closing, as we don't plan to add an
onErroroption tocreateMiddleware.On 2.x, the object form of
createMiddleware(onRequest/onBeforeResponse) is deprecated in favor of h3 middleware. The approaches in my previous comment cover errors from API routes, later middleware and server functions.If you need something those don't cover, please open a new issue with the errors you want to handle, the SolidStart version, and a small example.