Skip to content

Commit 7650505

Browse files
committed
site: fix handling of non-existent blog posts (#2439)
1 parent 0fe4195 commit 7650505

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Diff for: site/src/routes/blog/[slug].json.js

+3
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@ export function get(req, res) {
1616
'Cache-Control': `max-age=${5 * 60 * 1e3}` // 5 minutes
1717
});
1818
res.end(lookup.get(req.params.slug));
19+
} else {
20+
res.statusCode = 404;
21+
res.end(JSON.stringify({ message: 'not found' }));
1922
}
2023
}

Diff for: site/src/routes/blog/[slug].svelte

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script context="module">
22
export async function preload({ params }) {
3-
const post = await this.fetch(`blog/${params.slug}.json`).then(r => r.json());
4-
return { post };
3+
const res = await this.fetch(`blog/${params.slug}.json`);
4+
return res.ok ? { post: await res.json() } : this.error(404, 'Not found');
55
}
66
</script>
77

0 commit comments

Comments
 (0)