404 page if dynamic page content query doesn't return result

Stack
-macos
-wappler 6.8
-nodejs/mysql

I have a route with a parameter and I'd like to return a 404 page if the parameter is not found in my database table.

I'd like to do something like this server action but it's not working and throwing an error whether or not the parameter returns results form the single db query:

Hi,

Please post the exact error (or is it your error from the Throw Error step?)

Also, if you want a 404, you should use the Response step instead of Throw Error.

Throw Error raises an Exception which is propagated to the error handler, which in turn will return a 500 Internal Server Error or similar, not a 404 Not Found.

Btw I also wish there would be a way to cleanly generate a 404 Not Found page, but I don't know if it's possible... so you probably have to resort to the Response step.

Sorry @Apple do you mean this?

I mean have a Server Action step to render a 404 page directly :slight_smile: without doing any sort of redirect to a /404.html page or something

1 Like

I've changed it to a redirect. And get the following error.


That's expected, because it's redirecting, so it doesn't have any response body

If the problem is you don't see your browser redirecting, that's something I also came across, it seems you need to add a Dynamic Event to the Server Connect in question to redirect. Instead of doing a Redirect step on the Server Action, consider using a Set Value redirect

Instead of adding server connect component to the page, I added the server connect action to the page server side data section and it works using $_PARAM:


What's the difference between attaching Server Side Data vs doing it with Server Connect component? Or is it just how it works as it is and no other explanation?

If you want to do this at server level, you should use a "response" action (in core actions) which will terminate the action and return your chosen response code

Ok I added a response to my server action and when a route is found with matching brand from the database, the page just shows "success" how do you propose I load the content of the page?

Sorry,i misunderstood your problem, i thought you were referring to missing data rather than misding content page.

The link apple gave re custom error codes is the way to go