@ -9,6 +9,8 @@ import com.fasterxml.jackson.databind.node.TextNode;
import com.google.gson.JsonParser ;
import lombok.RequiredArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
import org.apache.commons.lang3.exception.ExceptionUtils ;
import org.springframework.http.HttpStatus ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.support.TransactionTemplate ;
import org.springframework.web.client.RestClientException ;
@ -69,6 +71,8 @@ import org.thingsboard.server.dao.subscription.PlatformFeature;
import org.thingsboard.server.dao.subscription.SubscriptionService ;
import org.thingsboard.server.exception.DataValidationException ;
import org.thingsboard.server.exception.EntitiesLimitExceededException ;
import org.thingsboard.server.exception.ThingsboardEntitiesLimitExceededResponse ;
import org.thingsboard.server.exception.ThingsboardErrorResponse ;
import org.thingsboard.server.queue.util.TbCoreComponent ;
import org.thingsboard.server.service.entitiy.AbstractTbEntityService ;
import org.thingsboard.server.service.entitiy.integration.TbIntegrationService ;
@ -242,7 +246,7 @@ public class DefaultDevicePackageService extends AbstractTbEntityService impleme
applied = change . apply ( ) ;
} catch ( StepFailure e ) {
log . warn ( "[{}] Device package {} failed on step [{}], nothing was changed" , tenantId , operation , e . stepKey , e . getCause ( ) ) ;
return DevicePackageResult . error ( userMessage ( e . getCause ( ) ) , e . stepKey ) ;
return DevicePackageResult . error ( userMessage ( e . getCause ( ) ) , e . stepKey , limitOf ( e . getCause ( ) ) ) ;
} catch ( RestClientException e ) {
log . error ( "[{}] IoT Hub request failed during the device package {}" , tenantId , operation , e ) ;
return DevicePackageResult . error ( "IoT Hub is unavailable. Try again later." , null ) ;
@ -1068,6 +1072,17 @@ public class DefaultDevicePackageService extends AbstractTbEntityService impleme
* The message the wizard shows : the ones validation and limits give , as they are ; anything else , e . g . a database
* error , as a common message , with the details in the log .
* /
static JsonNode limitOf ( Throwable e ) {
SubscriptionException subscription = ExceptionUtils . throwableOfType ( e , SubscriptionException . class ) ;
if ( subscription ! = null ) {
return JacksonUtil . valueToTree ( ThingsboardErrorResponse . ofSubscriptionViolation ( subscription . getMessage ( ) , subscription . getErrorCode ( ) ,
subscription . getEntry ( ) , subscription . getValue ( ) , HttpStatus . FORBIDDEN ) ) ;
}
EntitiesLimitExceededException entities = ExceptionUtils . throwableOfType ( e , EntitiesLimitExceededException . class ) ;
return entities = = null ? null
: JacksonUtil . valueToTree ( ThingsboardEntitiesLimitExceededResponse . of ( entities . getMessage ( ) , entities . getEntityType ( ) , entities . getLimit ( ) ) ) ;
}
static String userMessage ( Throwable e ) {
if ( e instanceof EntityVersionMismatchException ) {
return "Someone changed it meanwhile. Check the package again." ;