Skip to content

Commit

Permalink
Fix not found error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
corbanvilla committed Jan 23, 2024
1 parent daa29b8 commit cb8d602
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
16 changes: 0 additions & 16 deletions app/error.tsx

This file was deleted.

9 changes: 9 additions & 0 deletions app/issue/[issueNumber]/[articleSlug]/not-found.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Link from 'next/link'

export default function NotFound() {
return (
<div className="flex justify-center w-full">
<h2>Article not found!</h2>
</div>
)
}
8 changes: 5 additions & 3 deletions db/queries/articles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
wrapCache,
} from "../common";
import { format } from 'date-fns';
import { notFound } from 'next/navigation';

export const UNCATEGORIZED_CATEGORY: Category = { id: UNCATEGORIZED_CATEGORY_ID, name: UNCATEGORIZED_CATEGORY_NAME, slug: UNCATEGORIZED_CATEGORY_SLUG };

Expand Down Expand Up @@ -182,14 +183,15 @@ export const getArticle = async(slug: string): Promise<ArticlePage> => {
.limit(1);

if (!Array.isArray(article) || article.length === 0)
throw new Error('Article not found!');
notFound();

if (!article[0].markdown)
throw new Error('Article missing content!');
notFound();

// Don't render unpublished articles
if (article[0].publishedAt == null)
throw new Error('Article not found!');
notFound();
// throw new Error('Article not found!');

// attempt to get audio
const audioUri = await db.select({
Expand Down

1 comment on commit cb8d602

@vercel
Copy link

@vercel vercel bot commented on cb8d602 Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.