Merge pull request #2442 from sveltejs/gh-2439

site: fix handling of non-existent blog posts
pull/2451/head
Rich Harris 5 years ago committed by GitHub
commit b1312175bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,5 +16,8 @@ export function get(req, res) {
'Cache-Control': `max-age=${5 * 60 * 1e3}` // 5 minutes
});
res.end(lookup.get(req.params.slug));
} else {
res.statusCode = 404;
res.end(JSON.stringify({ message: 'not found' }));
}
}

@ -1,7 +1,7 @@
<script context="module">
export async function preload({ params }) {
const post = await this.fetch(`blog/${params.slug}.json`).then(r => r.json());
return { post };
const res = await this.fetch(`blog/${params.slug}.json`);
return res.ok ? { post: await res.json() } : this.error(404, 'Not found');
}
</script>

Loading…
Cancel
Save