Get a peek at our latest innovations at Sanity Product Day on Dec 8th →

404 Status Code - Is there a Way to Change the Status Code?

1 replies
Last updated: May 16, 2020

Hey there. I am doing a query by slug - and noticed that if the slug doesn't exist, the status code is still 200 with a result of null. Is there any way to make the query a different way that would return a 404? Example:

const query = `*[_type == "projects" && slug.current == $slug] {

May 15, 2020, 10:35 PM

Hia! All queries will return 200 as long as there's not a server error or similar, so you will have to check the result.

May 16, 2020, 4:47 PM Get the most out of your content is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Free to get started, and pay-as-you-go on all plans. Find out more.