Skip to content

Commit

Permalink
deploy: ebcd322
Browse files Browse the repository at this point in the history
  • Loading branch information
wimdeblauwe committed Sep 25, 2024
1 parent 908829e commit 92946f0
Showing 1 changed file with 82 additions and 11 deletions.
93 changes: 82 additions & 11 deletions current/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ <h1>Error Handling Spring Boot Starter</h1>
<li><a href="#error-messages">3.3. Error messages</a>
<ul class="sectlevel3">
<li><a href="#default-behaviour">3.3.1. Default behaviour</a></li>
<li><a href="#general-override-of-error-messages">3.3.2. General override of error messages</a></li>
<li><a href="#general-override-of-error-messages">3.3.2. General override of error messages</a>
<ul class="sectlevel4">
<li><a href="#exception">Exception</a></li>
<li><a href="#validation-annotation">Validation annotation</a></li>
</ul>
</li>
<li><a href="#field-specific-override-of-error-messages">3.3.3. Field specific override of error messages</a></li>
</ul>
</li>
Expand Down Expand Up @@ -121,7 +126,7 @@ <h1>Error Handling Spring Boot Starter</h1>
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>This documentation is for version 4.4.0.</p>
<p>This documentation is for version 4.5.0.</p>
</div>
</div>
</div>
Expand Down Expand Up @@ -700,9 +705,71 @@ <h4 id="default-behaviour"><a class="anchor" href="#default-behaviour"></a>3.3.1
<div class="sect3">
<h4 id="general-override-of-error-messages"><a class="anchor" href="#general-override-of-error-messages"></a>3.3.2. General override of error messages</h4>
<div class="paragraph">
<p>By using <code>error.handling.messages</code> property, it is possible to globally set an error message for a certain exception.
This is most useful for the validation messages.</p>
<p>By using <code>error.handling.messages</code> property, it is possible to globally set an error message for a certain exception or a certain validation annotation.</p>
</div>
<div class="sect4">
<h5 id="exception"><a class="anchor" href="#exception"></a>Exception</h5>
<div class="paragraph">
<p>Suppose you have this defined:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-properties" data-lang="properties">error.handling.messages.com.company.application.user.UserNotFoundException=The user was not found</code></pre>
</div>
</div>
<div class="paragraph">
<p>The response JSON:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-json" data-lang="json">{
"code": "USER_NOT_FOUND",
"message": "The user was not found" <i class="conum" data-value="1"></i><b>(1)</b>
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>The output uses the configured override.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>This can also be used for exception types that are not part of your own application.</p>
</div>
<div class="paragraph">
<p>For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-properties" data-lang="properties">error.handling.messages.jakarta.validation.ConstraintViolationException=There was a validation failure.</code></pre>
</div>
</div>
<div class="paragraph">
<p>Will output the following JSON:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-json" data-lang="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"
}
]
}</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="validation-annotation"><a class="anchor" href="#validation-annotation"></a>Validation annotation</h5>
<div class="paragraph">
<p>Suppose you have this defined:</p>
</div>
Expand Down Expand Up @@ -743,6 +810,7 @@ <h4 id="general-override-of-error-messages"><a class="anchor" href="#general-ove
<p>So you start with <code>error.handling.messages</code> and suffix with the name of the validation annotation used (<code>@NotBlank</code> in the above example).</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="field-specific-override-of-error-messages"><a class="anchor" href="#field-specific-override-of-error-messages"></a>3.3.3. Field specific override of error messages</h4>
<div class="paragraph">
Expand Down Expand Up @@ -1651,8 +1719,10 @@ <h4 id="authenticationentrypoint"><a class="anchor" href="#authenticationentrypo
import io.github.wimdeblauwe.errorhandlingspringbootstarter.mapper.HttpStatusMapper;

import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;

</span><span class="fold-block">public class WebSecurityConfiguration {
@Bean
Expand All @@ -1666,11 +1736,11 @@ <h4 id="authenticationentrypoint"><a class="anchor" href="#authenticationentrypo
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http,
UnauthorizedEntryPoint unauthorizedEntryPoint) throws Exception {
http.httpBasic().disable();
http.httpBasic(AbstractHttpConfigurer::disable);

http.authorizeHttpRequests().anyRequest().authenticated();
http.authorizeHttpRequests(customizer -&gt; customizer.anyRequest().authenticated());

http.exceptionHandling().authenticationEntryPoint(unauthorizedEntryPoint);<i class="conum" data-value="2"></i><b>(2)</b>
http.exceptionHandling(customizer -&gt; customizer.authenticationEntryPoint(unauthorizedEntryPoint));<i class="conum" data-value="2"></i><b>(2)</b>

return http.build();
}
Expand Down Expand Up @@ -1710,6 +1780,7 @@ <h4 id="accessdeniedhandler"><a class="anchor" href="#accessdeniedhandler"></a>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;

</span><span class="fold-block">public class WebSecurityConfiguration {

Expand All @@ -1724,11 +1795,11 @@ <h4 id="accessdeniedhandler"><a class="anchor" href="#accessdeniedhandler"></a>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 -&gt; customizer.anyRequest().authenticated());

http.exceptionHandling().accessDeniedHandler(accessDeniedHandler);<i class="conum" data-value="2"></i><b>(2)</b>
http.exceptionHandling(customizer -&gt; customizer.accessDeniedHandler(accessDeniedHandler));<i class="conum" data-value="2"></i><b>(2)</b>

return http.build();
}
Expand Down Expand Up @@ -2170,7 +2241,7 @@ <h2 id="support"><a class="anchor" href="#support"></a>6. Support</h2>
</div>
<div id="footer">
<div id="footer-text">
Last updated 2024-09-12 06:58:29 UTC
Last updated 2024-09-25 06:34:53 UTC
</div>
</div>
</div>
Expand Down

0 comments on commit 92946f0

Please sign in to comment.