error-handling
Mobile icon

Error Handling

Stable version 1.0.2 (Compatible with OutSystems 11)
Uploaded
 on 09 December 2021
 by 
5.0
 (4 ratings)
error-handling

Error Handling

Documentation
1.0.2

What does this plugin do?

In short, this plugin makes defining error messages (in validation logic) less cumbersome. Instead of copy/pasting or typing the same logic over and over again for each validation, this plugin only requires you to assign the function as an output of your error message.


How do I use this plugin?

First, start by making a normal validation tree as defined in the best practices. Here, we test if a validation is met by checking an if-statement. If the validation is not met, use the false branch to assign the error. Here is where the plugin comes in.

Inside the assign, we assign 2 output variables: IsError (Or IsSucces, depending on your way of working) and ErrorMessage.

The ErrMsg() function requires at least 2 inputs: the original ErrorMessage (so it can be appended) and the name of the attribute that triggered the error. Optionally, you can fill a third input to overwrite the default error message behavior to create a custom error message. This might be useful when we do not want the error message to look like this format: "Invalid value for required field [AttributeName]".

Using this function, automatically will append error messages if multiple errors are triggered in a row.

Example

Let's assume we want custom validation before creating a new user using the User_Create server action. The top part of the create action would look like this:

Here, we first validate the inputs before actually creating a new User record. If anything (or multiple things) go wrong, an error is thrown using the IsError boolean and the end-user will receive an ErrorMessage to explain what went wrong. Because multiple errors might have been triggered, we want to be able to append the ErrorMessage

Inside the validation, the action will look like this:

Since we want to make sure a user inputs both a Name and a valid Email, we check each of these attributes for a valid value. If the check fails, the error assignment is triggered. The assign might look like this:

Here, we set the IsError boolean to True so the action can detect there is an error. Furthermore, the ErrorMessage is assigned a new value using this plugin's function ErrMsg().

Let's assume both validation checks fail, the resulting output would be an IsError boolean set to True and an ErrorMessage looking like this:

"Invalid value for required field Name. Invalid value for required field Email."


If you require a custom ErrorMessage when the check fails, you can assign it using the 3rd parameter of the function. For example, we could change the ErrorMessage for the Email validation to ErrMsg(ErrorMessage,"Email","You entered an email address that is not valid, please make sure you use the right format.").


DltErr()

Similarly, it is possible to use the DltErr() function to quickly create errors specifically for the use case of checking identifiers before deleting a record. This is useful to make the end-user aware of a situation where the user tries to delete a record with an identifier that does not exist. Check the description of the function for more information.