How to return page 404 with a certain response of the server?
Unanswered
Great Dane posted this in #help-forum
Great DaneOP
Hello! Let me ask a question. If the page does not exist, then 404 is loaded.
Is it possible in addition to this if the record does'nt exist in the database to load the 404 page? The server returns 404 in the absence of a document with the requested ID. Here, a request for a server is performed in the getData function
And if the server has sent a response about no data, is it possible to load page 404? There is nothing about this in the documentation. Tell me, can Next.js do that? Or what needs to be done in this situation?
It is important that the page return the error code, since otherwise it may be indexed by Google, even if the page has been deleted. Thanks for attention.
Is it possible in addition to this if the record does'nt exist in the database to load the 404 page? The server returns 404 in the absence of a document with the requested ID. Here, a request for a server is performed in the getData function
async function getData() {
const res = await fetch('https://api.example.com/...')
if (!res.ok) {
throw new Error('Failed to fetch data')
}
return res.json()
}And if the server has sent a response about no data, is it possible to load page 404? There is nothing about this in the documentation. Tell me, can Next.js do that? Or what needs to be done in this situation?
It is important that the page return the error code, since otherwise it may be indexed by Google, even if the page has been deleted. Thanks for attention.