How can I create custom errors?
Now you can define custom error messages per Validation Rule which are going to be returned via an API Response when code validation or redemption fails due to the request not meeting validation rule criteria.
Custom error messages are by default visible only in the API response to the given request. Just like in the case of other Voucherify objects, you are free to decide how you would like to display them to your audience.
If you are new to the idea of API-first platforms, visit this article to learn more.
You may create your custom error messaging in the Validation Rules section or while creating a campaign.
Let's go to the Validation Rules section.
First, you may establish a default fallback error message applicable to all validation rule errors that have not been defined separately.
Next, you can add a unique error message for each validation rule.
For instance, you may create a campaign only for customers who have been with your company for a year. If customers outside of the "1-year anniversary" customer segment attempted at redeeming such voucher, Voucherify would block the attempt and will return a custom error message (e.g. "You do not meet segment criteria" or " You are not a "1-year anniversary" customer").
You can also create custom error messages programmatically.
The content of the custom error message is going to be returned in
error object under
If you don't specify any error message for a Validation Rule then the
error property will not be included in the API response.
Here is an exemplary API response containing the custom error message: