|
6 | 6 | import org.hswebframework.web.exception.BusinessException;
|
7 | 7 | import org.hswebframework.web.exception.NotFoundException;
|
8 | 8 | import org.hswebframework.web.exception.ValidationException;
|
| 9 | +import org.hswebframework.web.logger.ReactiveLogger; |
9 | 10 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
10 | 11 | import org.springframework.core.Ordered;
|
11 | 12 | import org.springframework.core.annotation.Order;
|
@@ -36,9 +37,9 @@ public class CommonErrorControllerAdvice {
|
36 | 37 |
|
37 | 38 | @ExceptionHandler
|
38 | 39 | @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
39 |
| - public Mono<ResponseMessage<?>> handleException(BusinessException e) { |
40 |
| - log.error(e.getMessage(), e); |
41 |
| - return Mono.just(ResponseMessage.error(e.getCode(), e.getMessage())); |
| 40 | + public Mono<ResponseMessage<Object>> handleException(BusinessException e) { |
| 41 | + return Mono.just(ResponseMessage.error(e.getCode(), e.getMessage())) |
| 42 | + .doOnEach(ReactiveLogger.onNext(r -> log.error(e.getMessage(), e))); |
42 | 43 | }
|
43 | 44 |
|
44 | 45 | @ExceptionHandler
|
@@ -119,64 +120,67 @@ public Mono<ResponseMessage<?>> handleException(javax.validation.ValidationExcep
|
119 | 120 |
|
120 | 121 | @ExceptionHandler
|
121 | 122 | @ResponseStatus(HttpStatus.GATEWAY_TIMEOUT)
|
122 |
| - public Mono<ResponseMessage<?>> handleException(TimeoutException e) { |
123 |
| - log.error(e.getMessage(), e); |
124 |
| - return Mono.just(ResponseMessage.error(504, "timeout", e.getMessage())); |
| 123 | + public Mono<ResponseMessage<Object>> handleException(TimeoutException e) { |
| 124 | + return Mono.just(ResponseMessage.error(504, "timeout", e.getMessage())) |
| 125 | + .doOnEach(ReactiveLogger.onNext(r -> log.error(e.getMessage(), e))); |
| 126 | + |
125 | 127 | }
|
126 | 128 |
|
127 | 129 | @ExceptionHandler
|
128 | 130 | @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
129 | 131 | @Order
|
130 |
| - public Mono<ResponseMessage<?>> handleException(RuntimeException e) { |
131 |
| - log.error(e.getMessage(), e); |
132 |
| - return Mono.just(ResponseMessage.error(e.getMessage())); |
| 132 | + public Mono<ResponseMessage<Object>> handleException(RuntimeException e) { |
| 133 | + return Mono.just(ResponseMessage.error(e.getMessage())) |
| 134 | + .doOnEach(ReactiveLogger.onNext(r -> log.error(e.getMessage(), e))); |
| 135 | + |
133 | 136 | }
|
134 | 137 |
|
135 | 138 | @ExceptionHandler
|
136 | 139 | @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
137 |
| - public Mono<ResponseMessage<?>> handleException(NullPointerException e) { |
138 |
| - log.error(e.getMessage(), e); |
139 |
| - return Mono.just(ResponseMessage.error(e.getMessage())); |
| 140 | + public Mono<ResponseMessage<Object>> handleException(NullPointerException e) { |
| 141 | + |
| 142 | + return Mono.just(ResponseMessage.error(e.getMessage())) |
| 143 | + .doOnEach(ReactiveLogger.onNext(r -> log.error(e.getMessage(), e))); |
140 | 144 | }
|
141 | 145 |
|
142 | 146 | @ExceptionHandler
|
143 | 147 | @ResponseStatus(HttpStatus.BAD_REQUEST)
|
144 |
| - public Mono<ResponseMessage<?>> handleException(IllegalArgumentException e) { |
145 |
| - log.error(e.getMessage(), e); |
146 |
| - return Mono.just(ResponseMessage.error(400, "illegal_argument", e.getMessage())); |
| 148 | + public Mono<ResponseMessage<Object>> handleException(IllegalArgumentException e) { |
| 149 | + return Mono.just(ResponseMessage.error(400, "illegal_argument", e.getMessage())) |
| 150 | + .doOnEach(ReactiveLogger.onNext(r -> log.error(e.getMessage(), e))); |
147 | 151 | }
|
148 | 152 |
|
149 | 153 | @ExceptionHandler
|
150 | 154 | @ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
|
151 |
| - public Mono<ResponseMessage<?>> handleException(MediaTypeNotSupportedStatusException e) { |
152 |
| - log.error(e.getMessage(), e); |
| 155 | + public Mono<ResponseMessage<Object>> handleException(MediaTypeNotSupportedStatusException e) { |
153 | 156 | return Mono.just(ResponseMessage
|
154 | 157 | .error(415, "unsupported_media_type", "不支持的请求类型")
|
155 |
| - .result(e.getSupportedMediaTypes())); |
| 158 | + .result(e.getSupportedMediaTypes())) |
| 159 | + .doOnEach(ReactiveLogger.onNext(r -> log.error(e.getMessage(), e))); |
156 | 160 | }
|
157 | 161 |
|
158 | 162 | @ExceptionHandler
|
159 | 163 | @ResponseStatus(HttpStatus.NOT_ACCEPTABLE)
|
160 |
| - public Mono<ResponseMessage<?>> handleException(NotAcceptableStatusException e) { |
161 |
| - log.error(e.getMessage(), e); |
| 164 | + public Mono<ResponseMessage<Object>> handleException(NotAcceptableStatusException e) { |
162 | 165 | return Mono.just(ResponseMessage
|
163 | 166 | .error(406, "not_acceptable_media_type", "不支持的响应类型")
|
164 |
| - .result(e.getSupportedMediaTypes())); |
| 167 | + .result(e.getSupportedMediaTypes())) |
| 168 | + .doOnEach(ReactiveLogger.onNext(r -> log.error(e.getMessage(), e))); |
165 | 169 | }
|
166 | 170 |
|
167 | 171 | @ExceptionHandler
|
168 | 172 | @ResponseStatus(HttpStatus.NOT_ACCEPTABLE)
|
169 |
| - public Mono<ResponseMessage<?>> handleException(MethodNotAllowedException e) { |
170 |
| - log.error(e.getMessage(), e); |
| 173 | + public Mono<ResponseMessage<Object>> handleException(MethodNotAllowedException e) { |
171 | 174 | return Mono.just(ResponseMessage
|
172 | 175 | .error(405, "method_not_allowed", "不支持的请求方法:" + e.getHttpMethod())
|
173 |
| - .result(e.getSupportedMethods())); |
| 176 | + .result(e.getSupportedMethods())) |
| 177 | + .doOnEach(ReactiveLogger.onNext(r -> log.error(e.getMessage(), e))); |
174 | 178 | }
|
175 | 179 |
|
176 | 180 | @ExceptionHandler
|
177 | 181 | @ResponseStatus(HttpStatus.BAD_REQUEST)
|
178 | 182 | public Mono<ResponseMessage<?>> handleException(ServerWebInputException e) {
|
179 |
| - Throwable exception=e; |
| 183 | + Throwable exception = e; |
180 | 184 | do {
|
181 | 185 | exception = exception.getCause();
|
182 | 186 | if (exception instanceof ValidationException) {
|
|
0 commit comments