Skip to content

Commit e7d1761

Browse files
committed
fix: 异常处理
1 parent ad36203 commit e7d1761

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

src/main/java/world/weibiansanjue/doctools/javadochub/controller/JavadocController.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,21 @@ private void extract(ModelAndView modelView,
8383

8484
log.info("extract javadoc. g={} a={} v={} p={}", groupId, artifactId, version, page);
8585

86+
modelView.addObject("groupId", groupId)
87+
.addObject("artifactId", artifactId)
88+
.addObject("artifactIds", repository.artifact(groupId))
89+
.addObject("version", version)
90+
.addObject("page", page)
91+
.setViewName("doc");
92+
8693
Versioning versioning = repository.version(groupId, artifactId);
94+
if (null == versioning) {
95+
modelView.addObject("version", null == version ? "latest" : version)
96+
.addObject("status", 404);
97+
return;
98+
}
8799
version = StringUtils.isEmpty(version) || "latest".equals(version) ? versioning.getRelease() : version;
88-
89-
modelView.addObject("groupId", groupId)
90-
.addObject("artifactId", artifactId)
91-
.addObject("artifactIds", repository.artifact(groupId))
92-
.addObject("version", version)
93-
.addObject("versions", versioning.getVersions())
94-
.addObject("page", page)
95-
.setViewName("doc");
100+
modelView.addObject("versions", versioning.getVersions());
96101

97102
int status = repository.store(groupId, artifactId, version);
98103
modelView.addObject("status", status);

src/main/java/world/weibiansanjue/doctools/javadochub/repository/Repository.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,15 @@ public Versioning version(String groupId, String artifactId) {
9393
String url = String.format("%s/%s/%s/%s", rep, groupId.replace(".", "/"), artifactId, "maven-metadata.xml");
9494
log.info("remote version. url={}", url);
9595

96-
ResponseEntity<Metadata> resp = restTemplate.getForEntity(url, Metadata.class);
96+
ResponseEntity<Metadata> resp = null;
97+
try {
98+
resp = restTemplate.getForEntity(url, Metadata.class);
99+
} catch (HttpClientErrorException hcee) {
100+
log.error("javadoc version 列表获取失败. hcee={}", hcee.getMessage());
101+
return null;
102+
}
97103
if (!resp.getStatusCode().is2xxSuccessful()) {
98-
return new Versioning();
104+
return null;
99105
}
100106
Versioning versioning = resp.getBody().getVersioning();
101107
Collections.reverse(versioning.getVersions());

src/main/resources/templates/doc.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
th:src="|/${groupId}/${artifactId}/${version}/${page}|" >
7575
</iframe>
7676
<h1 th:if="${status == 404}" align="center">😅 javadoc 不存在</h1>
77+
<h1 th:if="${status != 404 && status != 202}" align="center">😅 javadoc 加载失败,请重试</h1>
7778
</div>
7879

7980
</div>

0 commit comments

Comments
 (0)