Skip to content

Commit

Permalink
CAP Java Validation Error Translations
Browse files Browse the repository at this point in the history
  • Loading branch information
beckermarc authored Jan 21, 2025
1 parent 3afe228 commit 8eab800
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions java/event-handlers/indicating-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ messages.warn("my.message.key", paramNumber);
throw new ServiceException(ErrorStatuses.BAD_REQUEST, "my.message.key", paramNumber, originalException);
```

### Out-of-the-box Translations for Validation Error Messages

CAP Java provides out-of-the-box translation for error messages that originate from input validation annotations such as `@assert...` or `@mandatory` and security annotations `@requires` and `@restrict`.
The error messages are optimized for UI scenarios and avoid any technical references to entity names or element names. Message targets are used where appropriate to allow the UI to show the error message next to the affected UI element.
You can enable these translated error messages by setting [<Config java>cds.errors.defaultTranslations.enabled: true</Config>](../../java/developing-applications/properties#cds-errors-default-translations-enabled).

### Exporting the Default Messages

As of CAP Java 1.10.0, you can extract the available default messages as a resource bundle file for further processing (for example, translation). Therefore, the delivery artifact [cds-services-utils](https://search.maven.org/artifact/com.sap.cds/cds-services-utils) contains a resource bundle `cds-messages-template.properties` with all available error codes and default messages. Application developers can use this template to customize error messages thrown by the CAP Java SDK in the application.
Expand Down

0 comments on commit 8eab800

Please sign in to comment.