优化异常处理
This commit is contained in:
parent
831db77c0c
commit
2d976b7634
|
|
@ -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 -> {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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("该设备网关已启用");
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue