Is it possible to change the error message if the error occurred on the server side?
Problem:
Could you please tell me if I can change the error message if the error occurred on the server side? For example, I edit a row and get an error on the server side. In the browser, I only get "The server encountered an error and the field could not be updated". I would like to replace this message with the specific massage from the server side (for example "ERROR: Duplicate key value violates the uniqueness constraint. Such Id already exists").
Solution:
Yes, you can set the error message and include the token for the serverMessage. You can also include the path the message if it’s in a JSON object.
<zg-param name="serverErrorMessage" value="Server Error: [[serverMessage]]"></zg-param>
<zg-param name="serverErrorPath" value="errorMessage"></zg-param>
https://www.zinggrid.com/docs/api/tags/zg-param#zg-param-name-serverErrorMessage
We've created you a very basic full-stack zinggrid-nodejs-express-crud-example you will be using for reference. This basic demo is just to show you that the error message we set on the server will be displayed on the frontend (ZingGrid) as you wish. To see this in action:
- Install the dependencies
npm install
- Run the server with
npm run start
and visit http://localhost:8000/ - Try deleting any of the records.