✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

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] {
  name,
  slug,
  description,
  image,
  website
}[0]
`;

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.

https://www.sanity.io/docs/http-query#not-found-considered-harmless-bWaZca0V
May 16, 2020, 4:47 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?