Sfoglia il codice sorgente

优化异常处理

zhouhao 5 anni fa
parent
commit
2d976b7634

+ 2 - 2
jetlinks-components/gateway-component/src/main/java/org/jetlinks/community/gateway/supports/DefaultDeviceGatewayManager.java

@@ -31,10 +31,10 @@ public class DefaultDeviceGatewayManager implements DeviceGatewayManager, BeanPo
         }
         return propertiesManager
             .getProperties(id)
-            .switchIfEmpty(Mono.error(new UnsupportedOperationException("网关配置[" + id + "]不存在")))
+            .switchIfEmpty(Mono.error(()->new UnsupportedOperationException("网关配置[" + id + "]不存在")))
             .flatMap(properties -> Mono
                 .justOrEmpty(providers.get(properties.getProvider()))
-                .switchIfEmpty(Mono.error(new UnsupportedOperationException("不支持的网络服务[" + properties.getProvider() + "]")))
+                .switchIfEmpty(Mono.error(()->new UnsupportedOperationException("不支持的网络服务[" + properties.getProvider() + "]")))
                 .flatMap(provider -> provider
                     .createDeviceGateway(properties)
                     .flatMap(gateway -> {

+ 1 - 1
jetlinks-manager/network-manager/src/main/java/org/jetlinks/community/network/manager/service/DeviceGatewayConfigService.java

@@ -22,7 +22,7 @@ public class DeviceGatewayConfigService implements DeviceGatewayPropertiesManage
 
         return deviceGatewayService
             .findById(id)
-            .switchIfEmpty(Mono.error(new NotFoundException("该设备网关不存在")))
+            .switchIfEmpty(Mono.error(()->new NotFoundException("该设备网关不存在")))
             .map(deviceGatewayEntity -> {
                 DeviceGatewayProperties properties = new DeviceGatewayProperties();
                 FastBeanCopier.copy(deviceGatewayEntity, properties);

+ 1 - 1
jetlinks-manager/network-manager/src/main/java/org/jetlinks/community/network/manager/service/DeviceGatewayService.java

@@ -47,7 +47,7 @@ public class DeviceGatewayService extends GenericReactiveCrudService<DeviceGatew
     @Override
     public Mono<Integer> deleteById(Publisher<String> idPublisher) {
         return findById(Mono.from(idPublisher))
-            .switchIfEmpty(Mono.error(new NotFoundException("改设备网关不存在")))
+            .switchIfEmpty(Mono.error(()->new NotFoundException("改设备网关不存在")))
             .doOnNext(deviceGatewayEntity -> {
                 if (NetworkConfigState.enabled.equals(deviceGatewayEntity.getState())) {
                     throw new UnsupportedOperationException("该设备网关已启用");

+ 2 - 2
jetlinks-manager/network-manager/src/main/java/org/jetlinks/community/network/manager/web/NetworkConfigController.java

@@ -49,7 +49,7 @@ public class NetworkConfigController implements ReactiveServiceCrudController<Ne
     @PostMapping("/{id}/_start")
     public Mono<Void> start(@PathVariable String id) {
         return configService.findById(id)
-                .switchIfEmpty(Mono.error(new NotFoundException("配置[" + id + "]不存在")))
+                .switchIfEmpty(Mono.error(()->new NotFoundException("配置[" + id + "]不存在")))
                 .flatMap(conf -> configService.createUpdate()
                         .set(NetworkConfigEntity::getState, NetworkConfigState.enabled)
                         .where(conf::getId)
@@ -61,7 +61,7 @@ public class NetworkConfigController implements ReactiveServiceCrudController<Ne
     @PostMapping("/{id}/_shutdown")
     public Mono<Void> shutdown(@PathVariable String id) {
         return configService.findById(id)
-                .switchIfEmpty(Mono.error(new NotFoundException("配置[" + id + "]不存在")))
+                .switchIfEmpty(Mono.error(()->new NotFoundException("配置[" + id + "]不存在")))
                 .flatMap(conf -> configService.createUpdate()
                         .set(NetworkConfigEntity::getState, NetworkConfigState.disabled)
                         .where(conf::getId)