Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
blittle committed Nov 17, 2022
1 parent e09b8c1 commit 7b22b4a
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions packages/hydrogen-remix/routing/redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {HydrogenContext} from '..';
export async function notFoundMaybeRedirect(
request: Request,
context: HydrogenContext,
): Promise<void> {
): Promise<Response> {
const {pathname, search} = new URL(request.url);
const {urlRedirects} = await context.storefront.query<{
urlRedirects: {
Expand All @@ -17,14 +17,14 @@ export async function notFoundMaybeRedirect(
});

if (urlRedirects?.edges?.length) {
throw new Response(null, {
return new Response(null, {
status: 301,
headers: {
location: urlRedirects.edges[0]?.node?.target!,
},
});
} else {
throw new Response('Not found', {status: 404});
return new Response('Not found', {status: 404});
}
}

Expand Down
2 changes: 1 addition & 1 deletion templates/demo-store/app/components/SortFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState} from 'react';
import React, {useState} from 'react';
import {Heading, Button, Drawer as DrawerComponent} from '~/components';
import {Link, useLocation} from '@remix-run/react';
import type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export async function loader({params, request, context}: LoaderArgs) {
});

if (!collection) {
await notFoundMaybeRedirect(request, context);
throw await notFoundMaybeRedirect(request, context);
}

return json({collection});
Expand Down
2 changes: 1 addition & 1 deletion templates/demo-store/app/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export async function loader({request, params, context}: LoaderArgs) {
) {
// If the lang URL param is defined, yet we still are on `EN-US`
// the the lang param must be invalid, send to the 404 page
await notFoundMaybeRedirect(request, context);
throw await notFoundMaybeRedirect(request, context);
}

const {shop, hero} = await context.storefront.query<{
Expand Down
2 changes: 1 addition & 1 deletion templates/demo-store/app/routes/journal/$journalHandle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function loader({request, params, context}: LoaderArgs) {
});

if (!blog?.articleByHandle) {
await notFoundMaybeRedirect(request, context);
throw await notFoundMaybeRedirect(request, context);
}

const article = blog.articleByHandle;
Expand Down
2 changes: 1 addition & 1 deletion templates/demo-store/app/routes/pages/$pageHandle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function loader({request, params, context}: LoaderArgs) {
});

if (!page) {
await notFoundMaybeRedirect(request, context);
throw await notFoundMaybeRedirect(request, context);
}

return json(
Expand Down
2 changes: 1 addition & 1 deletion templates/demo-store/app/routes/policies/$policyHandle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function loader({request, params, context}: LoaderArgs) {
const policy = data.shop?.[policyName];

if (!policy) {
await notFoundMaybeRedirect(request, context);
throw await notFoundMaybeRedirect(request, context);
}

return json(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const loader = async ({params, request, context}: LoaderArgs) => {
});

if (!product) {
await notFoundMaybeRedirect(request, context);
throw await notFoundMaybeRedirect(request, context);
}

return defer({
Expand Down

0 comments on commit 7b22b4a

Please sign in to comment.