Skip to content

Commit d15b55a

Browse files
[cds^9.4] feat(node.js): translated error messages (#2087)
delivered with cds 9.4 Co-authored-by: sjvans <[email protected]>
1 parent fb39eda commit d15b55a

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

node.js/cds-i18n.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -674,11 +674,11 @@ Ensure you correctly understand how the config option `cds.i18n.folders` work be
674674
These are the current i18n entries for [`cds.i18n.messages`](#messages) used by the CAP runtime, which you can provide own translations for in your app-specific `_i18n/messages_<locale>.properties` files:
675675

676676
```properties
677-
MULTIPLE_ERRORS = Multiple errors occurred. Please see the details for more information.
678-
ASSERT_FORMAT = Value "{0}" is not in specified format "{1}"
679-
ASSERT_RANGE = Value {0} is not in specified range [{1}, {2}]
680-
ASSERT_ENUM = Value {0} is invalid according to enum declaration {{1}}
681-
ASSERT_NOT_NULL = Value is required
677+
MULTIPLE_ERRORS = Multiple errors occurred, see details below.
678+
ASSERT_FORMAT = Enter a value matching the pattern {1}.
679+
ASSERT_RANGE = Enter a value between {1} and {2}.
680+
ASSERT_ENUM = Enter one of the allowed values: {1}.
681+
ASSERT_MANDATORY = Provide the missing value.
682682
```
683683

684684
In addition the following HTTP status codes can be translated:

node.js/events.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,3 +612,21 @@ Content-Type: application/json
612612
> In production, error responses should never disclose internal information that could be exploited by attackers. To ensure that, all errors with a `5xx` status code are returned to the client with only the respective generic message (example: `500 Internal Server Error`).
613613
>
614614
> In very rare cases, you might want to return 5xx errors with a meaningful message to the client. This can be achieved with `err.$sanitize = false`. Use that option with care!
615+
616+
617+
## Translations for Validation Errors
618+
619+
For the following annotations/error codes, the runtime provides default translations:
620+
621+
| Annotation | Error Code |
622+
|-------------------------|---------------------------------|
623+
| `@mandatory` | ASSERT_MANDATORY<sup>(1)</sup> |
624+
| `@assert.range` | ASSERT_RANGE |
625+
| `@assert.range` on enum | ASSERT_ENUM |
626+
| `@assert.format` | ASSERT_FORMAT |
627+
| `@assert.target` | ASSERT_TARGET |
628+
629+
<sup>(1)</sup> Falls back to error code `ASSERT_NOT_NULL` if provided in custom translations.
630+
631+
These can be overridden by the known technique of providing [custom i18n messages](cds-i18n#localized-messages).
632+

0 commit comments

Comments
 (0)