In server actions, I have created an object “Response” with Status 501 and Text “Error email”.
On the client side I run this server action on a form and if error occurs I would like to display that text (“Error email”).
But when error occurs, I always get “Internal server Error”.
I am trying to notify the user that his email already exists in the system.
The check works perfectly for me with a SQL query.
But I don’t know any other way to notify the client from the server other than through “Response”.
What is the “Response.Text” attribute for if it cannot be accessed from the client?
You can use the validation step for this in the server action. It will return a validation error on the front end which you can use to trigger an alert/notify.
It should also work the way you set it up, just return a 400 error code. Then you can access the response text on the clienside and show it in an alert or notify.
You can explore the response of the server action in the developer tools in your browser under Network > HXR
For now I have solved it with response 599 and showing “lastError.response” in an Alert. This allows me to access the “Response.Text” attribute.
If I use response 400, the “Error” event is not fired.
if you work with form and server action lasterror does.t work. You can see status, but not any message from your response.text (response code 200). But if you use ‘data’ variable instead of ‘status’ you can see this text and do some notifications to user.