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:
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.
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?