|
1 | 1 | package net.cryptic_game.backend.admin;
|
2 | 2 |
|
| 3 | +import java.security.Principal; |
| 4 | +import java.util.stream.Collectors; |
| 5 | + |
| 6 | +import net.getnova.framework.core.GlobalErrorWebExceptionHandler; |
3 | 7 | import net.getnova.framework.core.NovaBanner;
|
4 | 8 | import org.springdoc.core.GroupedOpenApi;
|
| 9 | +import org.springframework.beans.factory.ObjectProvider; |
5 | 10 | import org.springframework.boot.autoconfigure.SpringBootApplication;
|
| 11 | +import org.springframework.boot.autoconfigure.web.ResourceProperties; |
| 12 | +import org.springframework.boot.autoconfigure.web.ServerProperties; |
| 13 | +import org.springframework.boot.autoconfigure.web.WebProperties; |
| 14 | +import org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler; |
6 | 15 | import org.springframework.boot.builder.SpringApplicationBuilder;
|
7 | 16 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
| 17 | +import org.springframework.boot.web.reactive.error.ErrorAttributes; |
| 18 | +import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler; |
| 19 | +import org.springframework.context.ApplicationContext; |
8 | 20 | import org.springframework.context.annotation.Bean;
|
| 21 | +import org.springframework.core.annotation.Order; |
9 | 22 | import org.springframework.http.HttpHeaders;
|
10 | 23 | import org.springframework.http.MediaType;
|
| 24 | +import org.springframework.http.codec.ServerCodecConfigurer; |
11 | 25 | import org.springframework.security.core.Authentication;
|
12 | 26 | import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
13 | 27 | import org.springframework.web.bind.annotation.GetMapping;
|
14 | 28 | import org.springframework.web.bind.annotation.RestController;
|
15 | 29 | import org.springframework.web.reactive.function.client.WebClient;
|
| 30 | +import org.springframework.web.reactive.result.view.ViewResolver; |
16 | 31 | import org.springframework.web.server.WebSession;
|
17 | 32 |
|
18 |
| -import java.security.Principal; |
19 |
| - |
20 | 33 | @SpringBootApplication
|
21 | 34 | @RestController
|
22 | 35 | @EnableConfigurationProperties(Config.class)
|
@@ -61,4 +74,27 @@ GroupedOpenApi serverApi() {
|
61 | 74 | .pathsToMatch("/server_management/**")
|
62 | 75 | .build();
|
63 | 76 | }
|
| 77 | + |
| 78 | + @Bean |
| 79 | + @Order(-2) |
| 80 | + public ErrorWebExceptionHandler errorWebExceptionHandler( |
| 81 | + final ErrorAttributes errorAttributes, |
| 82 | + final ResourceProperties resourceProperties, |
| 83 | + final WebProperties webProperties, |
| 84 | + final ApplicationContext applicationContext, |
| 85 | + final ServerProperties serverProperties, |
| 86 | + final ObjectProvider<ViewResolver> viewResolvers, |
| 87 | + final ServerCodecConfigurer serverCodecConfigurer |
| 88 | + ) { |
| 89 | + final AbstractErrorWebExceptionHandler exceptionHandler = new GlobalErrorWebExceptionHandler( |
| 90 | + errorAttributes, |
| 91 | + resourceProperties.hasBeenCustomized() ? resourceProperties : webProperties.getResources(), |
| 92 | + applicationContext, |
| 93 | + serverProperties.getError() |
| 94 | + ); |
| 95 | + exceptionHandler.setViewResolvers(viewResolvers.orderedStream().collect(Collectors.toList())); |
| 96 | + exceptionHandler.setMessageWriters(serverCodecConfigurer.getWriters()); |
| 97 | + exceptionHandler.setMessageReaders(serverCodecConfigurer.getReaders()); |
| 98 | + return exceptionHandler; |
| 99 | + } |
64 | 100 | }
|
0 commit comments