We’ve all seen those error messages that don’t make any sense. Have you ever wanted to replace an error messages with your own custom error messages?

It’s actually not too difficult to replace these error messages.
An example of Custom error messages
Table of Contents
Imagine that we have a button in out app that will update a record using the Patch function. Obviously the following example will give us an error.

In the OnError property of the App, we could specify how we want an error to appear. In the example below we are adding some text in front of the error message.

This will result in the following error message when we click that button.

There have been a few situation in Power Apps where the user only gets “An unknown error occurred”, with the above property you could replace those messages with something more useful.
We could also user the error code to decide what we want to do. This could be a notification, but anything is possible. Maybe we can even fix the issue within the app.
Notify("My Custom Message:" & First(Errors(Accounts)).Error, NotificationType.Error) Power Apps knows the following kind of errors:
| ErrorKind | Description |
|---|---|
| ErrorKind.Conflict | Another change was made to the same record, resulting in a change conflict. Use the Refresh function to reload the record and try the change again. |
| ErrorKind.ConstraintViolation | One or more constraints have been violated. |
| ErrorKind.CreatePermission | An attempt was made to create a record, and the current user doesn’t have permission to create records. |
| ErrorKind.DeletePermission | An attempt was made to delete a record, and the current user doesn’t have permission to delete records. |
| ErrorKind.EditPermission | An attempt was made to edit a record, and the current user doesn’t have permission to edit records. |
| ErrorKind.GeneratedValue | An attempt was made to change a column that the data source generates automatically. |
| ErrorKind.MissingRequired | The value for a required column is missing from the record. |
| ErrorKind.None | There’s no error. |
| ErrorKind.NotFound | An attempt was made to edit or delete a record, but the record couldn’t be found. Another user may have changed the record. |
| ErrorKind.ReadOnlyValue | An attempt was made to change a column that’s read only. |
| ErrorKind.Sync | An error was reported by the data source. Check the Message column for more information. |
| ErrorKind.Unknown | There was an error, but of an unknown kind. |
| ErrorKind.Validation | There was a general validation issue detected, that didn’t fit one of the other kinds. |
Now it is easy to create a switch statement to handle each of the error types in a slightly different way.
Discover more from SharePains
Subscribe to get the latest posts sent to your email.