From 92946f01b21d161d4605fe1670617cffabdcac58 Mon Sep 17 00:00:00 2001 From: wimdeblauwe Date: Wed, 25 Sep 2024 06:35:26 +0000 Subject: [PATCH] deploy: ebcd322fe08b9c41b5399630070ec461780a23c2 --- current/index.html | 93 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 82 insertions(+), 11 deletions(-) diff --git a/current/index.html b/current/index.html index 641a6cb..32e2973 100644 --- a/current/index.html +++ b/current/index.html @@ -72,7 +72,12 @@

Error Handling Spring Boot Starter

  • 3.3. Error messages
  • @@ -121,7 +126,7 @@

    Error Handling Spring Boot Starter

    -

    This documentation is for version 4.4.0.

    +

    This documentation is for version 4.5.0.

    @@ -700,9 +705,71 @@

    3.3.1

    3.3.2. 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:

    +
    +
    +
    +
    error.handling.messages.com.company.application.user.UserNotFoundException=The user was not found
    +
    +
    +
    +

    The response JSON:

    +
    +
    +
    +
    {
    +  "code": "USER_NOT_FOUND",
    +  "message": "The user was not found" (1)
    +}
    +
    +
    +
    + + + + + +
    1The output uses the configured override.
    +
    +
    +

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

    +
    +
    +

    For example:

    +
    +
    +
    +
    error.handling.messages.jakarta.validation.ConstraintViolationException=There was a validation failure.
    +
    +
    +
    +

    Will output the following 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:

    @@ -743,6 +810,7 @@

    3.3.3. Field specific override of error messages

    @@ -1651,8 +1719,10 @@

    public class WebSecurityConfiguration { @Bean @@ -1666,11 +1736,11 @@

    (2) + http.exceptionHandling(customizer -> customizer.authenticationEntryPoint(unauthorizedEntryPoint));(2) return http.build(); } @@ -1710,6 +1780,7 @@

    3 import org.springframework.context.annotation.Bean; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; public class WebSecurityConfiguration { @@ -1724,11 +1795,11 @@

    3 @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http, AccessDeniedHandler accessDeniedHandler) throws Exception { - http.httpBasic().disable(); + http.httpBasic(AbstractHttpConfigurer::disable); - http.authorizeHttpRequests().anyRequest().authenticated(); + http.authorizeHttpRequests(customizer -> customizer.anyRequest().authenticated()); - http.exceptionHandling().accessDeniedHandler(accessDeniedHandler);(2) + http.exceptionHandling(customizer -> customizer.accessDeniedHandler(accessDeniedHandler));(2) return http.build(); } @@ -2170,7 +2241,7 @@

    6. Support