Skip to content

Commit

Permalink
replace throw new Error with just string
Browse files Browse the repository at this point in the history
  • Loading branch information
michenly committed May 25, 2024
1 parent 8084273 commit 3899d44
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion templates/skeleton/app/routes/$.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {LoaderFunctionArgs} from '@shopify/remix-oxygen';

export async function loader({request, response}: LoaderFunctionArgs) {
response!.status = 404;
throw new Error(`${new URL(request.url).pathname} not found`);
throw `${new URL(request.url).pathname} not found`;
}

export default function CatchAllPage() {
Expand Down
2 changes: 1 addition & 1 deletion templates/skeleton/app/routes/[sitemap.xml].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function loader({

if (!data) {
response!.status = 404;
throw new Error('No data found');
throw 'No data found';
}

const sitemap = generateSitemap({data, baseUrl: new URL(request.url).origin});
Expand Down
20 changes: 10 additions & 10 deletions templates/skeleton/app/routes/account.addresses.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function action({request, context, response}: ActionFunctionArgs) {
? String(form.get('addressId'))
: null;
if (!addressId) {
throw new Error('You must provide an address id.');
throw 'You must provide an address id.';
}

// this will ensure redirecting to login never happen for mutatation
Expand Down Expand Up @@ -94,15 +94,15 @@ export async function action({request, context, response}: ActionFunctionArgs) {
);

if (errors?.length) {
throw new Error(errors[0].message);
throw errors[0].message;
}

if (data?.customerAddressCreate?.userErrors?.length) {
throw new Error(data?.customerAddressCreate?.userErrors[0].message);
throw data?.customerAddressCreate?.userErrors[0].message;
}

if (!data?.customerAddressCreate?.customerAddress) {
throw new Error('Customer address create failed.');
throw 'Customer address create failed.';
}

return {
Expand Down Expand Up @@ -133,15 +133,15 @@ export async function action({request, context, response}: ActionFunctionArgs) {
);

if (errors?.length) {
throw new Error(errors[0].message);
throw errors[0].message;
}

if (data?.customerAddressUpdate?.userErrors?.length) {
throw new Error(data?.customerAddressUpdate?.userErrors[0].message);
throw data?.customerAddressUpdate?.userErrors[0].message;
}

if (!data?.customerAddressUpdate?.customerAddress) {
throw new Error('Customer address update failed.');
throw 'Customer address update failed.';
}

return {
Expand All @@ -168,15 +168,15 @@ export async function action({request, context, response}: ActionFunctionArgs) {
);

if (errors?.length) {
throw new Error(errors[0].message);
throw errors[0].message;
}

if (data?.customerAddressDelete?.userErrors?.length) {
throw new Error(data?.customerAddressDelete?.userErrors[0].message);
throw data?.customerAddressDelete?.userErrors[0].message;
}

if (!data?.customerAddressDelete?.deletedAddressId) {
throw new Error('Customer address delete failed.');
throw 'Customer address delete failed.';
}

return {error: null, deletedAddress: addressId};
Expand Down
2 changes: 1 addition & 1 deletion templates/skeleton/app/routes/account.orders.$id.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function loader({params, context, response}: LoaderFunctionArgs) {
);

if (errors?.length || !data?.order) {
throw new Error('Order not found');
throw 'Order not found';
}

const {order} = data;
Expand Down
4 changes: 2 additions & 2 deletions templates/skeleton/app/routes/account.profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ export async function action({request, context, response}: ActionFunctionArgs) {
);

if (errors?.length) {
throw new Error(errors[0].message);
throw errors[0].message;
}

if (!data?.customerUpdate?.customer) {
throw new Error('Customer profile update failed.');
throw 'Customer profile update failed.';
}

return {
Expand Down
2 changes: 1 addition & 1 deletion templates/skeleton/app/routes/account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function loader({context, response}: LoaderFunctionArgs) {
);

if (errors?.length || !data?.customer) {
throw new Error('Customer not found');
throw 'Customer not found';
}

response!.headers.set('Cache-Control', 'no-cache, no-store, must-revalidate');
Expand Down
2 changes: 1 addition & 1 deletion templates/skeleton/app/routes/api.predictive-search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async function fetchPredictiveSearchResults({
});

if (!data) {
throw new Error('No data returned from Shopify API');
throw 'No data returned from Shopify API';
}

const searchResults = normalizePredictiveSearchResults(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function loader({params, context, response}: LoaderFunctionArgs) {

if (!articleHandle || !blogHandle) {
response!.status = 404;
throw new Error('Not found');
throw 'Not found';
}

const {blog} = await context.storefront.query(ARTICLE_QUERY, {
Expand Down
4 changes: 2 additions & 2 deletions templates/skeleton/app/routes/blogs.$blogHandle._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function loader({

if (!params.blogHandle) {
response!.status = 404;
throw new Error('Blog not found');
throw 'Blog not found';
}

const {blog} = await storefront.query(BLOGS_QUERY, {
Expand All @@ -31,7 +31,7 @@ export async function loader({

if (!blog?.articles) {
response!.status = 404;
throw new Error('Not found');
throw 'Not found';
}

return {blog};
Expand Down
4 changes: 2 additions & 2 deletions templates/skeleton/app/routes/cart.$lines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function loader({

if (result.errors?.length || !cartResult) {
response!.status = 410;
throw new Error('Link may be expired. Try checking the URL.');
throw 'Link may be expired. Try checking the URL.';
}

// Update cart id in cookie
Expand All @@ -74,7 +74,7 @@ export async function loader({
response!.headers.set('Location', cartResult.checkoutUrl);
throw response;
} else {
throw new Error('No checkout URL found');
throw 'No checkout URL found';
}
}

Expand Down
4 changes: 2 additions & 2 deletions templates/skeleton/app/routes/cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function action({request, context, response}: ActionFunctionArgs) {
const {action, inputs} = CartForm.getFormInput(formData);

if (!action) {
throw new Error('No action provided');
throw 'No action provided';
}

let result: CartQueryDataReturn;
Expand Down Expand Up @@ -53,7 +53,7 @@ export async function action({request, context, response}: ActionFunctionArgs) {
break;
}
default:
throw new Error(`${action} cart action is not defined`);
throw `${action} cart action is not defined`;
}

const cartId = result?.cart?.id;
Expand Down
2 changes: 1 addition & 1 deletion templates/skeleton/app/routes/collections.$handle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function loader({

if (!collection) {
response!.status = 404;
throw new Error(`Collection ${handle} not found`);
throw `Collection ${handle} not found`;
}
return {collection};
}
Expand Down
4 changes: 2 additions & 2 deletions templates/skeleton/app/routes/pages.$handle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const meta: MetaFunction<typeof loader> = ({data}) => {

export async function loader({params, context, response}: LoaderFunctionArgs) {
if (!params.handle) {
throw new Error('Missing page handle');
throw 'Missing page handle';
}

const {page} = await context.storefront.query(PAGE_QUERY, {
Expand All @@ -18,7 +18,7 @@ export async function loader({params, context, response}: LoaderFunctionArgs) {

if (!page) {
response!.status = 404;
throw new Error('Not Found');
throw 'Not Found';
}

return {page};
Expand Down
4 changes: 2 additions & 2 deletions templates/skeleton/app/routes/policies.$handle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const meta: MetaFunction<typeof loader> = ({data}) => {
export async function loader({params, context, response}: LoaderFunctionArgs) {
if (!params.handle) {
response!.status = 404;
throw new Error('No handle was passed in');
throw 'No handle was passed in';
}

const policyName = params.handle.replace(
Expand All @@ -37,7 +37,7 @@ export async function loader({params, context, response}: LoaderFunctionArgs) {

if (!policy) {
response!.status = 404;
throw new Error('Could not find the policy');
throw 'Could not find the policy';
}

return {policy};
Expand Down
2 changes: 1 addition & 1 deletion templates/skeleton/app/routes/policies._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export async function loader({context, response}: LoaderFunctionArgs) {

if (!policies.length) {
response!.status = 404;
throw new Error('No policies found');
throw 'No policies found';
}

return {policies};
Expand Down
2 changes: 1 addition & 1 deletion templates/skeleton/app/routes/products.$handle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function loader({
const {storefront} = context;

if (!handle) {
throw new Error('Expected product handle to be defined');
throw 'Expected product handle to be defined';
}

// await the query for the critical product data
Expand Down
2 changes: 1 addition & 1 deletion templates/skeleton/app/routes/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function loader({request, context}: LoaderFunctionArgs) {
});

if (!data) {
throw new Error('No search data returned from Shopify API');
throw 'No search data returned from Shopify API';
}

const totalResults = Object.values(data).reduce((total, value) => {
Expand Down

0 comments on commit 3899d44

Please sign in to comment.