Skip to content

Commit 7248cce

Browse files
committed
优化请求api的报错逻辑
1 parent 2fcb77f commit 7248cce

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

CHANGELOG.MD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
更新日志文档,版本顺序从新到旧,最新版本在最前(上)面。
44

5+
# 1.0.16
6+
7+
- 优化请求api的报错逻辑
8+
59
# 1.0.15
610

711
- 刷新Token后立刻刷新请求头

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
group=run.ikaros.plugin
22
description=A pan115 plugin for ikaros.
3-
version=1.0.15
3+
version=1.0.16

src/main/java/run/ikaros/plugin/pan115/repository/DefaultPan115Repository.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
1111
import org.springframework.http.HttpHeaders;
1212
import org.springframework.http.HttpStatus;
13+
import org.springframework.http.HttpStatusCode;
1314
import org.springframework.http.MediaType;
1415
import org.springframework.stereotype.Component;
1516
import org.springframework.util.Assert;
@@ -163,6 +164,16 @@ public Mono<AttachmentDriver> refreshToken(AttachmentDriver driver) {
163164
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
164165
.bodyValue(body)
165166
.exchangeToMono(rsp -> rsp.bodyToMono(Pan115Result.class))
167+
.flatMap(r -> {
168+
if (r == null) {
169+
return Mono.error(new Pan115RequestFailException(HttpStatusCode.valueOf(400),
170+
"request pan 115 api fail with result is null"));
171+
}
172+
if (!r.getState()) {
173+
return Mono.error(new Pan115RequestFailException(r.getMessage(), r.getCode()));
174+
}
175+
return Mono.just(r);
176+
})
166177
.filter(r -> Objects.nonNull(r) && r.getState())
167178
.flatMap(r -> {
168179
if (!r.getState()) {

0 commit comments

Comments
 (0)