Global error handling

Avatar

Avatar

ajur

Avatar

ajur

ajur

05-03-2021

Hello to everybody,

I developed a form with a custom submit action which calls a service. This service calls an API endpoint to save some data. In this process anything can go wrong like connection errors and so on. So then my service returns an error code 500.

In this case the AEM Form shows an alert box with an AEM Forms error code "AEM-AF-901-004". But I don't want to show this alert box. In all backend error cases, I will show to the user a styled error message above the form like "Something went wrong. Please try again later!". I can't find a description how to define such global error messages. But actually it is a common case, right? 

Can you give me some links or hints how to do it?

Regards, Andrea

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

PulkitJain

Employee

Avatar

PulkitJain

Employee

PulkitJain
Employee

26-03-2021

@ajur 

AEM Forms provides out-of-the-box success and error handlers (client-side functions that are executed based on the server response) for form submissions. Here you can write rules[0] at the form level to override default handlers.

Hopefully, this should serve the purpose.

 

 

[0] - https://experienceleague.adobe.com/docs/experience-manager-65/forms/adaptive-forms-advanced-authorin... 

Answers (1)

Answers (1)

Avatar

Avatar

ajur

Avatar

ajur

ajur

12-03-2021

Hello,

I found a solution for my problem but nowhere a good documentation/HowTo of it. So following steps I've done:

  1. Create a text component within you form, where the error message should be shown and type in your error text.
  2. In the properties dialog give the text component a "speaking" name, tick the "Hide object" checkbox to hide it initially and save the properties.
  3. Select the form container and open the rules editor.
  4. Create a new rule and select "WHEN form submission fails  THEN show 'name of your text component'".
  5. Save the rule
  6. Open the properties dialog of the form and tick the checkbox "Use asynchronous submission" in section "Submission" and save the properties.

Unfortunately I don't know how to do it without asynchronous submission. Maybe I have to change something in my custom submit action to add a parameter which I can check in a rule or something different.

Regards, Andrea