Skip to content

Commit

Permalink
♻️ Refactoring code. #I44W82 token失效后 处理后pig-auth 项目未捕获到失效错误json提示 前台…
Browse files Browse the repository at this point in the history
…返回的还是500错误 无法获取到失效提示json 跳转登录页
  • Loading branch information
lltx committed Aug 11, 2021
1 parent 4b97369 commit 435eae5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public void serialize(PigAuth2Exception value, JsonGenerator gen, SerializerProv
gen.writeObjectField("code", CommonConstants.FAIL);
gen.writeStringField("msg", value.getMessage());
gen.writeStringField("data", value.getErrorCode());
// 资源服务器会读取这个字段
gen.writeStringField("error", value.getMessage());
gen.writeEndObject();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ public RestTemplate lbRestTemplate() {
@Override
@SneakyThrows
public void handleError(ClientHttpResponse response) {
if (response.getRawStatusCode() != HttpStatus.BAD_REQUEST.value()) {
super.handleError(response);
// 当认证中心返回 400 或者 424 错误码不抛异常,交给资源服务自行处理
if (response.getRawStatusCode() == HttpStatus.FAILED_DEPENDENCY.value()
|| response.getRawStatusCode() == HttpStatus.BAD_REQUEST.value()) {
return;
}

// 原有异常处理逻辑
super.handleError(response);
}
});
return restTemplate;
Expand Down

0 comments on commit 435eae5

Please sign in to comment.