Commit 5433d77801e3ff17718138954716f5883946a589

Authored by 云中非
1 parent 82bb0c36

fix: DataValidationException异常返回400

@@ -43,6 +43,7 @@ import org.thingsboard.server.common.data.exception.ThingsboardException; @@ -43,6 +43,7 @@ import org.thingsboard.server.common.data.exception.ThingsboardException;
43 import org.thingsboard.server.common.data.yunteng.core.Result; 43 import org.thingsboard.server.common.data.yunteng.core.Result;
44 import org.thingsboard.server.common.data.yunteng.core.exception.ThingsKitException; 44 import org.thingsboard.server.common.data.yunteng.core.exception.ThingsKitException;
45 import org.thingsboard.server.common.msg.tools.TbRateLimitsException; 45 import org.thingsboard.server.common.msg.tools.TbRateLimitsException;
  46 +import org.thingsboard.server.dao.exception.DataValidationException;
46 import org.thingsboard.server.service.security.exception.AuthMethodNotSupportedException; 47 import org.thingsboard.server.service.security.exception.AuthMethodNotSupportedException;
47 import org.thingsboard.server.service.security.exception.JwtExpiredTokenException; 48 import org.thingsboard.server.service.security.exception.JwtExpiredTokenException;
48 import org.thingsboard.server.service.security.exception.UserPasswordExpiredException; 49 import org.thingsboard.server.service.security.exception.UserPasswordExpiredException;
@@ -134,6 +135,9 @@ public class ThingsboardErrorResponseHandler extends ResponseEntityExceptionHand @@ -134,6 +135,9 @@ public class ThingsboardErrorResponseHandler extends ResponseEntityExceptionHand
134 handleAuthenticationException((AuthenticationException) exception, response); 135 handleAuthenticationException((AuthenticationException) exception, response);
135 }else if(exception instanceof ThingsKitException){ 136 }else if(exception instanceof ThingsKitException){
136 handleThingsKitException((ThingsKitException)exception, response); 137 handleThingsKitException((ThingsKitException)exception, response);
  138 + }else if(exception instanceof DataValidationException){
  139 + response.setStatus(HttpStatus.BAD_REQUEST.value());
  140 + mapper.writeValue(response.getWriter(), exception.getMessage());
137 } 141 }
138 else { 142 else {
139 response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); 143 response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());