|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package com.supervision.config;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.supervision.domain.GlobalResult;
|
|
|
|
|
import com.supervision.exception.BusinessException;
|
|
|
|
@ -47,7 +48,7 @@ public class ResponseConfig implements ResponseBodyAdvice<Object> {
|
|
|
|
|
public Object beforeBodyWrite(Object o, @Nullable MethodParameter methodParameter, @Nullable MediaType mediaType,
|
|
|
|
|
@Nullable Class<? extends HttpMessageConverter<?>> aClass, @Nullable ServerHttpRequest serverHttpRequest,
|
|
|
|
|
@Nullable ServerHttpResponse serverHttpResponse) {
|
|
|
|
|
serverHttpResponse.getHeaders().set("Content-Type","application/json");
|
|
|
|
|
serverHttpResponse.getHeaders().set("Content-Type", "application/json");
|
|
|
|
|
|
|
|
|
|
if (Objects.isNull(o)) {
|
|
|
|
|
return GlobalResult.ok(null, "success");
|
|
|
|
@ -99,7 +100,7 @@ public class ResponseConfig implements ResponseBodyAdvice<Object> {
|
|
|
|
|
// 格式化错误信息
|
|
|
|
|
String errorMsg = exception.getBindingResult().getFieldErrors().stream()
|
|
|
|
|
.map(e -> e.getField() + ":" + e.getDefaultMessage()).collect(Collectors.joining("、"));
|
|
|
|
|
return GlobalResult.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), "参数验证异常", errorMsg);
|
|
|
|
|
return GlobalResult.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), errorMsg, "参数验证异常");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -112,7 +113,7 @@ public class ResponseConfig implements ResponseBodyAdvice<Object> {
|
|
|
|
|
@ExceptionHandler(Exception.class)
|
|
|
|
|
public GlobalResult<?> validationExceptionResponse(Exception exception) {
|
|
|
|
|
log.error(exception.getMessage(), exception);
|
|
|
|
|
return GlobalResult.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), "未知错误", exception.getMessage());
|
|
|
|
|
return GlobalResult.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), exception.getMessage(), "未知错误");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|