Skip to content

Commit

Permalink
Merge pull request #6951 from JerryWu1234/6950_fix_demo
Browse files Browse the repository at this point in the history
fix: a bug that error in the middleware occurs 404
  • Loading branch information
shairez authored Jan 9, 2025
2 parents 104fefc + 6a17e2c commit 6e3bb16
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
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
9 changes: 5 additions & 4 deletions packages/docs/src/routes/demo/qwikcity/middleware/layout.tsx
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);
});
}

0 comments on commit 6e3bb16

Please sign in to comment.