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
Middleware in a plugin file is able to intercept and catch routeLoader$ errors, but server$ can only call next() but catching errors doesn't work - the error is always returned immediately to the browser.
The usecase for this is to catch specific network errors (in this case ConnectErrors from connectrpc) and convert them into ServerErrors to return the correct status codes, and also to log errors with structured logging.
For example:
import{typeRequestHandler}from"@builder.io/qwik-city";exportconstonRequest: RequestHandler=async({ url, next })=>{constisServer=url.search.startsWith("?qfunc=");if(isServer){console.log("server$ middleware triggerd");}else{console.log("routeLoader$ middleware triggerd");}try{awaitnext();}catch(err){if(isServer){// <------------------------ This never runs ------------------->console.log("caught server$ error");}else{console.log("caught routeLoader$ error");}}};
Which component is affected?
Qwik City (routing)
Describe the bug
Middleware in a plugin file is able to intercept and catch routeLoader$ errors, but server$ can only call next() but catching errors doesn't work - the error is always returned immediately to the browser.
The usecase for this is to catch specific network errors (in this case ConnectErrors from connectrpc) and convert them into ServerErrors to return the correct status codes, and also to log errors with structured logging.
For example:
Reproduction
https://github.com/DustinJSilk/qwik-server-middleware-error/tree/main
Steps to reproduce
Run the app and view errors in the terminal
System Info
Additional Information
No response
The text was updated successfully, but these errors were encountered: