Error Handling for the API

Currently, in Decidim we are using some exceptions to handle API responses, aiming to serve both input (receiving data through API) and output (sending data through API).

At the moment there are 4 categories of exceptions that are being handled:

System Errors

Authorization errors

Validation errors

  • Not Found Error - NOT_FOUND_ERROR, is triggered when the requested record does not exist in database, or is in a state where you should not have access to it (moderated, belongs to an unpublished component, belongs to a private process where the requesting user does not have access)

  • Validation Error - VALIDATION_ERROR, is triggered when the requesting user performs an action that contains an error. This is equivalent to the flash messages displayed on the Website.

  • Attribute Validation Error - ATTRIBUTE_VALIDATION_ERROR, is triggered when the requesting user submits a request to alter a resource that has an error. This is equivalent to the validation errors in the HTTP forms.

Internationalization errors

  • Locale Error - LOCALE_ERROR, is triggered when there is a problem with the internationalization, for example, a missing translation, a missing interpolation to the output string

  • Invalid Locale Error - INVALID_LOCALE_ERROR, is triggered when the provided locale is invalid or not supported by the system, for example when an unknown locale code is used or a locale that is not enabled for the current organization