Error Handling

Every action a user performs with Shortlist has the (hopefully small) possibly of encountering an error.

The most common type of error you will encounter are validation errors, but other possibilities include permissions, restrictions, third party constraints and configurations or implementation issues.

By Request Type

Depending on the source of the action, the error details will be available from a variety of different sources.

GET request

Most standard shortlist interactions will be via GET requests. In this case if an action fails the user will be redirected back to the referral url. You can access the errors with the {{ craft.shortlist.error }} variable like :

{% if craft.shortlist.error %}
<div class="alert alert-error">
    {{ craft.shortlist.error }}
{% endif %}

Details on craft.shortlist.error() usage

POST request

All the same actions that can be triggered via GET requests can be triggered via POST requests. Check out the full action reference for more details on the specific paths you'll need.

When an action is triggered via a POST request we can return the full post request details and attached errors back to the page. In this case you can pull the errors for specific fields as well as the general overall errors. This is especially useful for lists and items that have additional fields assigned, as each field could have a separate error attached.

When you get the posted object back you'll have an array of errors for the overall request, and also specific errors attached to fields in the standard Craft format.

AJAX request

When actions are triggered via AJAX we return the result as a json array automatically. If the action fails you'll have an array of errors included in the response. These can be mapped directly back to specific elements as however you need.