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

fix: a bug that error in the middleware occurs 404 #6951

Merged
merged 11 commits into from
Jan 9, 2025
5 changes: 5 additions & 0 deletions .changeset/gorgeous-garlics-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@builder.io/qwik': patch
---

fix a bug that error in the middleware occurs 404
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { type RequestHandler } from '@builder.io/qwik-city';
export const onRequest: RequestHandler = async ({ next }) => {
try {
await next();
} catch (error) {
if (
} catch (error: any) {
if (error?.message === 'ERROR: Demonstration of an error response.') {
return await next();
} else if (
error &&
typeof error === 'object' &&
'message' in error &&
typeof error.message === 'string' &&
error.message == 'ERROR: Demonstration of an error response.'
typeof error.message === 'string'
) {
// ignore this error
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ export const head: DocumentHead = () => {
};
};

export const onGet: RequestHandler = ({ url, exit: exitMiddlewares }) => {
export const onGet: RequestHandler = ({
error,
url,
exit: exitMiddlewares,
}) => {
if (url.pathname === "/qwikcity-test/catchall-error/") {
throw error(500, "ERROR: Demonstration of an error response.");
}

if (url.pathname === "/qwikcity-test/catchall/") {
// special case catchall
return;
Expand Down
7 changes: 7 additions & 0 deletions starters/e2e/qwikcity/catchall.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ function tests() {
const status = response.status();
expect(status).toBe(404);
});

test("Error Catchall", async ({ context }) => {
const page = await context.newPage();
const response = (await page.goto("/qwikcity-test/catchall-error/"))!;
const status = response.status();
expect(status).toBe(500);
});
}
Loading