I would like to intercept the response in Gatsby v3 from a page and return 404 based on some conditions while having the same page html content generated by Gatsby.
In practice, lets say that I have
src/pages/profile.js
and some client routes that are attached to it. For example, profile/:userId/:blogId, for example. If the userId or profileId do not exists, the page html should be returned with status code 404 but same content generated by gatsby.
Now, I tried looking into gatsby functions but that feature is not created for that purpose. Also, I looked into gatsby SSR and that feature is also not created for that purpose, at least as far as I researched.
Also, found this bug report in gatsby, but the last comment says its solved in some other ticket but the other ticket is about DEV_SSR, and does not talk about intercepting the response. When targeting a route with DEV_SSR === true, page-data.json does have a 404 status code but the actual html page (the first request sent to the server) is 200.
EDIT:
So to clarify, as far as I understand, the html page exists, and it is there but needs to be returned with status code 404. That is also true for the default 404.html that comes with Gatsby installed. Even if that default 404 page is rendered, it is returned with status 200, not 404, but the content is something like "404, page does not exist".