Skip to content

Commit

Permalink
docs: Add documentation on how to override the message of an exception
Browse files Browse the repository at this point in the history
Fixes #103
  • Loading branch information
wimdeblauwe committed Sep 24, 2024
1 parent 88ad86e commit 7236fc6
Showing 1 changed file with 52 additions and 2 deletions.
54 changes: 52 additions & 2 deletions src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,58 @@ The response JSON:

==== General override of error messages

By using `error.handling.messages` property, it is possible to globally set an error message for a certain exception.
This is most useful for the validation messages.
By using `error.handling.messages` property, it is possible to globally set an error message for a certain exception or a certain validation annotation.

===== Exception

Suppose you have this defined:

[source,properties]
----
error.handling.messages.com.company.application.user.UserNotFoundException=The user was not found
----

The response JSON:

[source,json]
----
{
"code": "USER_NOT_FOUND",
"message": "The user was not found" //<.>
}
----

<.> The output uses the configured override.

This can also be used for exception types that are not part of your own application.

For example:

[source,properties]
----
error.handling.messages.jakarta.validation.ConstraintViolationException=There was a validation failure.
----

Will output the following JSON:

[source,json]
----
{
"code": "VALIDATION_FAILED",
"message": "There was a validation failure.",
"fieldErrors": [
{
"code": "INVALID_SIZE",
"property": "name",
"message": "size must be between 10 and 2147483647",
"rejectedValue": "",
"path": "name"
}
]
}
----

===== Validation annotation

Suppose you have this defined:

Expand Down

0 comments on commit 7236fc6

Please sign in to comment.