Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Validation and Error Messages

Validation and Error Messages

When a user takes an action that violates a business state or provides invalid input, an error is generated in Commerce Engine.

Types of Errors

Errors generated by Commerce Engine produce one of two results:

  • A collection of of com.elasticpath.common.dto.StructuredErrorMessage objects.
  • An InvalidBusinessStateException or EpValidationException exception, from which a collection of StructuredErrorMessage objects can be extracted.

StructuredErrorMessage objects are consumable by Cortex API resources. This allows you to present a localized version of the error message to the user if needed, allowing the user to resolve the cause of the error.

How Errors are Generated

Errors generated by Commerce Engine fall into two categories:

  • Constraint violations are typically a result of bad user input. For example, attempting to fill in an email into a phone number field. Constraint violations generate an EpValidationException exception, from which a collection of com.elasticpath.common.dto.StructuredErrorMessage objects can be extracted.
  • Invalid business state errors are typically a result of a business state that is incompatible with the user's intent, or impermissible by the business logic within Commerce Engine. For example, attempting to purchase an item that is out of stock. Business state errors generate an InvalidBusinessStateException, from which a collection of StructuredErrorMessage objects can be extracted.