Skip to content
This repository has been archived by the owner on Mar 12, 2023. It is now read-only.

Fix Internal Server Error when accessing a unfounded post #161

Merged
merged 1 commit into from Jan 8, 2023

Conversation

shmn7iii
Copy link
Contributor

@shmn7iii shmn7iii commented Jan 8, 2023

存在しないポストへアクセスすると 500 エラーが起きていたので修正PRです。

概要

https://easy-notion-blog-otoyo.vercel.app/blog/hoge のような存在しない slug へアクセスすると Internal Server Error が発生する。

app/blog/[slug]/page.tsx では post が見つからなかった場合リダイレクトが走る仕様になっているが、 app/blog/[slug]/head.tsx では post が見つからない場合も post.Title 等で呼び出しが起こるため以下のようなエラーが発生する。

2023-01-08T08:13:40.693Z	3abfe53b-a7f8-4446-961c-7294ad96b3bc	ERROR	TypeError: Cannot read properties of null (reading 'Title')
    at BlogSlugHead (/var/task/.next/server/app/blog/[slug]/page.js:440:21)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

対応内容

app/blog/[slug]/head.tsx において、 post が見つからなかった場合は空の <DocumentHead/> を返すように変更しました。

@vercel
Copy link

vercel bot commented Jan 8, 2023

Someone is attempting to deploy a commit to a Personal Account owned by @otoyo on Vercel.

@otoyo first needs to authorize it.

Copy link
Owner

@otoyo otoyo left a comment

Choose a reason for hiding this comment

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

修正ありがとうございます!

@vercel
Copy link

vercel bot commented Jan 8, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
easy-notion-blog ✅ Ready (Inspect) Visit Preview Jan 8, 2023 at 8:48AM (UTC)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants