Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐞] server$ middleware cannot catch errors #7183

Open
DustinJSilk opened this issue Dec 20, 2024 · 0 comments
Open

[🐞] server$ middleware cannot catch errors #7183

DustinJSilk opened this issue Dec 20, 2024 · 0 comments
Labels
STATUS-1: needs triage New issue which needs to be triaged TYPE: bug Something isn't working

Comments

@DustinJSilk
Copy link
Contributor

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:

import { type RequestHandler } from "@builder.io/qwik-city";

export const onRequest: RequestHandler = async ({ url, next }) => {
  const isServer = url.search.startsWith("?qfunc=");

  if (isServer) {
    console.log("server$ middleware triggerd");
  } else {
    console.log("routeLoader$ middleware triggerd");
  }

  try {
    await next();
  } catch (err) {
    if (isServer) {
      // <------------------------ This never runs ------------------->
      console.log("caught server$ error");
    } else {
      console.log("caught routeLoader$ error");
    }
  }
};

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

N/A

Additional Information

No response

@DustinJSilk DustinJSilk added STATUS-1: needs triage New issue which needs to be triaged TYPE: bug Something isn't working labels Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
STATUS-1: needs triage New issue which needs to be triaged TYPE: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant