Skip to content

Commit b2c5ed4

Browse files
committed
增加一些人性化的出错信息提示代码
1 parent f38447e commit b2c5ed4

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/main/java/com/github/binarywang/demo/wx/mp/config/WxMpConfiguration.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.binarywang.demo.wx.mp.config;
22

3+
import java.util.List;
34
import java.util.Map;
45
import java.util.stream.Collectors;
56

@@ -80,20 +81,23 @@ public static Map<String, WxMpService> getMpServices() {
8081
@Bean
8182
public Object services() {
8283
// 代码里getConfigs()处报错的同学,请注意仔细阅读项目说明,你的IDE需要引入lombok插件!!!!
83-
mpServices = this.properties.getConfigs()
84-
.stream()
85-
.map(a -> {
86-
WxMpInMemoryConfigStorage configStorage = new WxMpInMemoryConfigStorage();
87-
configStorage.setAppId(a.getAppId());
88-
configStorage.setSecret(a.getSecret());
89-
configStorage.setToken(a.getToken());
90-
configStorage.setAesKey(a.getAesKey());
91-
92-
WxMpService service = new WxMpServiceImpl();
93-
service.setWxMpConfigStorage(configStorage);
94-
routers.put(a.getAppId(), this.newRouter(service));
95-
return service;
96-
}).collect(Collectors.toMap(s -> s.getWxMpConfigStorage().getAppId(), a -> a));
84+
final List<WxMpProperties.MpConfig> configs = this.properties.getConfigs();
85+
if (configs == null) {
86+
throw new RuntimeException("大哥,拜托先看下项目首页的说明(readme文件),添加下相关配置,注意别配错了!");
87+
}
88+
89+
mpServices = configs.stream().map(a -> {
90+
WxMpInMemoryConfigStorage configStorage = new WxMpInMemoryConfigStorage();
91+
configStorage.setAppId(a.getAppId());
92+
configStorage.setSecret(a.getSecret());
93+
configStorage.setToken(a.getToken());
94+
configStorage.setAesKey(a.getAesKey());
95+
96+
WxMpService service = new WxMpServiceImpl();
97+
service.setWxMpConfigStorage(configStorage);
98+
routers.put(a.getAppId(), this.newRouter(service));
99+
return service;
100+
}).collect(Collectors.toMap(s -> s.getWxMpConfigStorage().getAppId(), a -> a, (o, n) -> o));
97101

98102
return Boolean.TRUE;
99103
}

0 commit comments

Comments
 (0)