Skip to content

Commit 972a9ae

Browse files
committed
packageEdit: DRY error handling code
Sentry logging isn't needed in UI component, it's handled by entry.server.tsx on server and RouteErrorBoundary on client.
1 parent 6191e0b commit 972a9ae

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

apps/cyberstorm-remix/app/p/packageEdit.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
4040
];
4141
};
4242

43+
const package404 = new Response("Package not found", { status: 404 });
44+
4345
export async function loader({ params }: LoaderFunctionArgs) {
4446
const { communityId, namespaceId, packageId } = params;
4547

4648
if (!communityId || !namespaceId || !packageId) {
47-
throw new Response("Package not found", { status: 404 });
49+
throw package404;
4850
}
4951

5052
try {
@@ -65,12 +67,7 @@ export async function loader({ params }: LoaderFunctionArgs) {
6567
permissions: undefined,
6668
};
6769
} catch (error) {
68-
if (error instanceof ApiError) {
69-
throw new Response("Package not found", { status: 404 });
70-
} else {
71-
// REMIX TODO: Add sentry
72-
throw error;
73-
}
70+
throw error instanceof ApiError ? package404 : error;
7471
}
7572
}
7673

@@ -79,7 +76,7 @@ export async function clientLoader({ params }: LoaderFunctionArgs) {
7976
const { communityId, namespaceId, packageId } = params;
8077

8178
if (!communityId || !namespaceId || !packageId) {
82-
throw new Response("Package not found", { status: 404 });
79+
throw package404;
8380
}
8481

8582
try {
@@ -116,11 +113,7 @@ export async function clientLoader({ params }: LoaderFunctionArgs) {
116113
permissions: permissions,
117114
};
118115
} catch (error) {
119-
if (error instanceof ApiError) {
120-
throw new Response("Package not found", { status: 404 });
121-
} else {
122-
throw error;
123-
}
116+
throw error instanceof ApiError ? package404 : error;
124117
}
125118
}
126119

0 commit comments

Comments
 (0)