AccessValidator improvements

This commit is contained in:
YevhenBondarenko 2020-11-09 18:09:24 +02:00
parent 75686ac167
commit 6d90dc8420

View File

@ -53,6 +53,7 @@ import org.thingsboard.server.dao.customer.CustomerService;
import org.thingsboard.server.dao.device.DeviceProfileService;
import org.thingsboard.server.dao.device.DeviceService;
import org.thingsboard.server.dao.entityview.EntityViewService;
import org.thingsboard.server.dao.exception.IncorrectParameterException;
import org.thingsboard.server.dao.rule.RuleChainService;
import org.thingsboard.server.dao.tenant.TenantService;
import org.thingsboard.server.dao.user.UserService;
@ -152,7 +153,11 @@ public class AccessValidator {
new FutureCallback<DeferredResult<ResponseEntity>>() {
@Override
public void onSuccess(@Nullable DeferredResult<ResponseEntity> result) {
onSuccess.accept(response, currentUser.getTenantId(), entityId);
try {
onSuccess.accept(response, currentUser.getTenantId(), entityId);
} catch (Exception e) {
onFailure(e);
}
}
@Override
@ -404,9 +409,9 @@ public class AccessValidator {
public static void handleError(Throwable e, final DeferredResult<ResponseEntity> response, HttpStatus defaultErrorStatus) {
ResponseEntity responseEntity;
if (e != null && e instanceof ToErrorResponseEntity) {
if (e instanceof ToErrorResponseEntity) {
responseEntity = ((ToErrorResponseEntity) e).toErrorResponseEntity();
} else if (e != null && e instanceof IllegalArgumentException) {
} else if (e instanceof IllegalArgumentException || e instanceof IncorrectParameterException) {
responseEntity = new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
} else {
responseEntity = new ResponseEntity<>(defaultErrorStatus);