Commit bc3e6564 by 黄超华

网关统一异常处理

1 parent e99cd7a5
......@@ -25,14 +25,9 @@ public class GlobalErrorAttributes extends DefaultErrorAttributes {
if (Objects.isNull(options)) return assembleError(request);
Map<String, Object> map = super.getErrorAttributes(request, options);
if (getError(request) instanceof GlobalException) {
GlobalException ex = (GlobalException) getError(request);
map.put(R.MSG_KEY, ex.getMessage());
map.put(R.CODE_KEY, ex.getStatus().value());
return map;
}
map.put(R.CODE_KEY, map.getOrDefault("status", HttpStatus.INTERNAL_SERVER_ERROR.value()));
map.put(R.MSG_KEY, "System Error , Check logs!");
Throwable throwable = getError(request);
map.put(R.MSG_KEY, throwable.getMessage());
map.put(R.CODE_KEY, HttpStatus.INTERNAL_SERVER_ERROR.value());
return map;
}
......
......@@ -75,21 +75,16 @@ public class JWTAuthGlobalFilter implements GlobalFilter, Ordered {
return chain.filter(exchange);
}
}
//从请求头中取出token
String token = exchange.getRequest().getHeaders().getFirst(HttpHeaders.AUTHORIZATION);
//未携带token或token在黑名单内
if (token == null || token.isEmpty()) {
log.info("url {} token is empty", url);
return loginResponse(exchange, token);
}
//验证token
// TODO: 2020/11/5 如果失效会报错,在失效情况下,失效刷新时间范围内,允许刷新
DecodedJWT decodedJWT = gatewayJwtUtils.verify(token, gatewayService);
if (decodedJWT == null) {
log.info("url {} token decoded fail", url);
return loginResponse(exchange, token);
}
ServerHttpRequest mutableReq = appendRequestHeaders(exchange, decodedJWT.getId());
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!