Custom error messages
You can define a custom error message for each validation rule. When code validation fails due to not meeting rule criteria, error messages will be returned via API.
Contents:
By default, custom error messages are visible only in the API response to the given request. However, just like with other objects, you are free to decide how you would like to display them to your audience. There are two types of error messages. The standard error message is displayed when a violation occurs on one of 16 application-defined errors.
On the other hand, the validation rule message is displayed when a violation occurs on a validation rule you defined. Additionally, for validation rule violations, you can specify a fallback error message that will be displayed when no error message is defined for a particular rule. You can define custom error messages for validation rules both via API or Dashboard. For custom standard error messages, you can provide definitions in the Dashboard and view the custom definitions but not define them in the API.
Create custom standard error message
You may customize a standard error message. This customization is especially useful for creating language-specific error messages.
Translate a total of 16 standard error messages, some of which are listed below, to a local language.
Note that these error messages are supported only in one language, with one translation group per project; you cannot support two languages or more simultaneously in one translation group.
- Voucher disabled - the voucher's 'active' property is equal to 'false'
- Voucher not active - when the current date is before the voucher's start date; the attempt to redeem occurs before the voucher's active timeframe
- Voucher not active now - when an attempt is made to redeem the voucher outside of its specified validity window; the attempt occurs on a day other than specified in the defined timeframe
- Voucher expired - when the voucher has expired
- Quantity exceeded - when the voucher redemption quantity is exceeded
- Promotion inactive - when the promotion is inactive because it has been disabled, has not started yet, has expired, and so on
- Promotion not active now - when an attempt is made to obtain a discount outside of the promotion's specified validity window
- Referrer not permitted to redeem - when the referral code is being redeemed by the referrer
This list includes only a handful of standard error messages you can translate. The application contains more errors, such as missing customers, missing orders, and exceeded gift amounts. To set the text for your translation, go to Error Messages under the Project Settings tab in the Home section.
Then click on Create new translations group.
Choose Redemption & Validation from the drop-down list.
Click on Add new locale.
For each of the error messages listed, enter the customized message Text that you would like to have displayed when the error occurs.
Finally, click Save and then Save again.
Your custom standard error messages are ready and are available in the API responses.
In the example below, the redemption fails because an attempt to redeem the voucher occurs outside of its valid timeframe. The voucher not active now error message is returned with the customized message
property in the error
object.
Create custom validation rule error message
You may create your custom error messaging in the Validation Rules section or while creating a campaign. Use the New builder to create custom error messages.
If you are not yet familiar with the concept of validation rules, visit this article to get started.
When creating a validation rule, click Add error message. You can then type the message that will be returned when a customer violates this validation rule.
Fallback error message
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.
Custom error message
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 to redeem such a voucher, Voucherify would block the attempt and return a custom error message (e.g., "You do not meet segment criteria" or " You are not a "1-year anniversary" customer").
Create custom validation rule error messages via API
You can also create custom error messages for validation rule errors programmatically. Go here to learn more details.
The content of the custom error message is going to be returned in the error
object under message
property.
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 validation API response containing the custom error message: