fix some exception handling logic
This commit is contained in:
parent
253dd6f79a
commit
c02a0b3544
@ -123,7 +123,6 @@ public class ContextInfoBuilderAspect {
|
||||
return pjpArgs;
|
||||
}
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
private void fillContextInfoWithRequestBeforeRemoteAuth(ContextInfo contextInfo, HttpServletRequest request) {
|
||||
SystemAndDeviceInfo sdInfo = new SystemAndDeviceInfo();
|
||||
@ -149,8 +148,7 @@ public class ContextInfoBuilderAspect {
|
||||
contextInfo.setVisitTo(request.getHeader(AuthConstants.VISIT_TO));
|
||||
}
|
||||
|
||||
////以上都是还没有去remote auth之前的动作
|
||||
|
||||
//// 以上都是还没有去remote auth之前的动作
|
||||
|
||||
private String remoteAuth(HttpServletRequest httpRequest, ContextInfo contextInfo) {
|
||||
String authResultJson;
|
||||
@ -188,6 +186,7 @@ public class ContextInfoBuilderAspect {
|
||||
String url = EnvEnum.getValueByKey(customerEnv);
|
||||
AuthException.error(CharSequenceUtil.isNotEmpty(url), "There is no correct path to request");
|
||||
|
||||
String response = null;
|
||||
try {
|
||||
HttpRequest request = HttpRequest.get(url).header(AuthConstants.HEADER_TOKEN, contextInfo.getToken())
|
||||
.header(AuthConstants.HEADER_TERMINAL, contextInfo.getTerminalInfo().getRawTerminalString())
|
||||
@ -203,7 +202,10 @@ public class ContextInfoBuilderAspect {
|
||||
// 有的URI,是归属于企业级的、有的归属于项目级,guess=newTerminalString
|
||||
// 有的URI,缺少部分header是正常的,我就没必要guess,有的有必要。
|
||||
|
||||
String response = request.execute().body();
|
||||
response = request.execute().body();
|
||||
} catch (HttpException e) {
|
||||
throw new AuthException("call pudge get/user error. token=" + contextInfo.getToken());
|
||||
}
|
||||
|
||||
try {
|
||||
TypeReference<Map<String, Object>> mapTypeReference = new TypeReference<Map<String, Object>>() {
|
||||
@ -219,12 +221,12 @@ public class ContextInfoBuilderAspect {
|
||||
} else {
|
||||
throw new AuthException("无法解析鉴权认证请求的返回值,token=" + contextInfo.getToken());
|
||||
}
|
||||
} catch (AuthException e) {
|
||||
throw e; // re-throw
|
||||
} catch (Exception e) {
|
||||
throw new AuthException("解析鉴权认证请求出错, token=" + contextInfo.getToken(), e);
|
||||
}
|
||||
} catch (HttpException e) {
|
||||
throw new AuthException("call pudge get/user error. token=" + contextInfo.getToken());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -235,7 +237,8 @@ public class ContextInfoBuilderAspect {
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
private String buildLegacyGuessMissedReqStringForRemoteAuth(ContextInfo contextInfo, HttpServletRequest originalRequest) {
|
||||
private String buildLegacyGuessMissedReqStringForRemoteAuth(ContextInfo contextInfo,
|
||||
HttpServletRequest originalRequest) {
|
||||
LegacyGuessMissedReq req = new LegacyGuessMissedReq();
|
||||
req.setOriginalUrl(originalRequest.getRequestURI());
|
||||
req.setHeaderOuId(contextInfo.getOuId());
|
||||
@ -247,8 +250,7 @@ public class ContextInfoBuilderAspect {
|
||||
return JSONUtil.toJsonStr(req);
|
||||
}
|
||||
|
||||
|
||||
///以下都是 remote auth 之后的动作
|
||||
/// 以下都是 remote auth 之后的动作
|
||||
|
||||
public void buildContextInfoByRemoteAuthResponse(ContextInfo contextInfo, String authResultJson) {
|
||||
log.info("buildUserInfo-->authResultJson:{},contextInfo:{}", authResultJson, JSONUtil.toJsonStr(contextInfo));
|
||||
@ -296,8 +298,7 @@ public class ContextInfoBuilderAspect {
|
||||
contextInfo.setSaasTenantId(rsp.getSaasTenantId());
|
||||
}
|
||||
if (LegacyGuessMissedRsp.ST_GUESS_OK.equals(rsp.getGuessTerminal())) {
|
||||
contextInfo.setTerminalInfo(
|
||||
new TerminalInfo(rsp.getNewTerminal()));
|
||||
contextInfo.setTerminalInfo(new TerminalInfo(rsp.getNewTerminal()));
|
||||
}
|
||||
if (LegacyGuessMissedRsp.ST_GUESS_OK.equals(rsp.getGuessWorkspace())) {
|
||||
contextInfo.setWorkspaceId(rsp.getWorkspaceId());
|
||||
@ -309,8 +310,7 @@ public class ContextInfoBuilderAspect {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///以下都是工具函数
|
||||
/// 以下都是工具函数
|
||||
|
||||
public static Long nullSafeParseLong(String input) {
|
||||
if (input == null)
|
||||
@ -319,7 +319,11 @@ public class ContextInfoBuilderAspect {
|
||||
return 0L;
|
||||
if ("undefined".equals(input))
|
||||
return 0L;
|
||||
try {
|
||||
return Long.valueOf(input);
|
||||
} catch (NumberFormatException e) {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user