1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.bremersee.exception;
18
19 import org.springframework.http.HttpStatusCode;
20 import org.springframework.util.ObjectUtils;
21 import org.springframework.web.reactive.function.client.WebClientResponseException;
22
23
24
25
26
27
28 public class RestApiExceptionMapperForWebFlux extends RestApiExceptionMapperForWeb {
29
30
31
32
33
34
35
36 public RestApiExceptionMapperForWebFlux(
37 RestApiExceptionMapperProperties properties,
38 String applicationName) {
39 super(properties, applicationName);
40 }
41
42 @Override
43 protected HttpStatusCode detectHttpStatus(Throwable exception, Object handler) {
44 if (exception instanceof WebClientResponseException cre) {
45 return cre.getStatusCode();
46 }
47 return super.detectHttpStatus(exception, handler);
48 }
49
50 @Override
51 protected String getError(Throwable exception, HttpStatusCode httpStatusCode) {
52 if ((exception instanceof WebClientResponseException cre)
53 && !(ObjectUtils.isEmpty(cre.getStatusText()))) {
54 return cre.getStatusText();
55 }
56 return super.getError(exception, httpStatusCode);
57 }
58 }