♻️ Refactoring code. #I44W82 token失效后 处理后pig-auth 项目未捕获到失效错误json提示 前台返回的还是500错误 无法获取到失效提示json 跳转登录页

This commit is contained in:
wjie 2021-08-11 13:35:19 +08:00
parent 4b97369107
commit 435eae5ad0
2 changed files with 9 additions and 2 deletions

View File

@ -42,6 +42,8 @@ public class PigAuth2ExceptionSerializer extends StdSerializer<PigAuth2Exception
gen.writeObjectField("code", CommonConstants.FAIL);
gen.writeStringField("msg", value.getMessage());
gen.writeStringField("data", value.getErrorCode());
// 资源服务器会读取这个字段
gen.writeStringField("error", value.getMessage());
gen.writeEndObject();
}

View File

@ -75,9 +75,14 @@ public class PigResourceServerAutoConfiguration {
@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;