refactor(support): 优化 OpenApiInterceptor 中的代码结构
- 将请求头验证逻辑移至 HandlerMethod 判断之后 -减少了不必要的代码嵌套,提高了代码可读性
This commit is contained in:
parent
5f21899c62
commit
47cd8d9963
|
@ -23,12 +23,12 @@ public class OpenApiInterceptor implements HandlerInterceptor {
|
|||
|
||||
@Override
|
||||
public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler) {
|
||||
String header = request.getHeader("X-API-KEY");
|
||||
if (StrUtil.isBlank(header)) {
|
||||
throw new MessageException("请求头缺失");
|
||||
}
|
||||
log.info("apiKey:{} {} 请求:{}", header, LocalDateTime.now(), request.getRequestURI());
|
||||
if (handler instanceof HandlerMethod handlerMethod) {
|
||||
String header = request.getHeader("X-API-KEY");
|
||||
if (StrUtil.isBlank(header)) {
|
||||
throw new MessageException("请求头缺失");
|
||||
}
|
||||
log.info("apiKey:{} {} 请求:{}", header, LocalDateTime.now(), request.getRequestURI());
|
||||
CheckOpenApi methodAnnotation = handlerMethod.getMethodAnnotation(CheckOpenApi.class);
|
||||
if (methodAnnotation != null) {
|
||||
List<String> openApiKeys = methodAnnotation.value().getOpenApiKeys();
|
||||
|
|
Loading…
Reference in New Issue