From 696d36ba251236946c14300384bd48116132b2cd Mon Sep 17 00:00:00 2001 From: Camelia Dumitru Date: Thu, 7 Nov 2024 19:31:10 +0000 Subject: [PATCH] Catching more exceptions --- .../orcid/api/filters/ApiRateLimitFilter.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/orcid-pub-web/src/main/java/org/orcid/api/filters/ApiRateLimitFilter.java b/orcid-pub-web/src/main/java/org/orcid/api/filters/ApiRateLimitFilter.java index 8225957d42..867807893c 100644 --- a/orcid-pub-web/src/main/java/org/orcid/api/filters/ApiRateLimitFilter.java +++ b/orcid-pub-web/src/main/java/org/orcid/api/filters/ApiRateLimitFilter.java @@ -123,20 +123,23 @@ protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServl } boolean isAnonymous = (clientId == null); LocalDate today = LocalDate.now(); + try { + if (isAnonymous) { + if (!isWhiteListed(ipAddress)) { + LOG.info("ApiRateLimitFilter anonymous request for ip: " + ipAddress); + this.rateLimitAnonymousRequest(ipAddress, today, httpServletResponse); + } - if (isAnonymous) { - if (!isWhiteListed(ipAddress)) { - LOG.info("ApiRateLimitFilter anonymous request for ip: " + ipAddress); - this.rateLimitAnonymousRequest(ipAddress, today, httpServletResponse); + } else { + LOG.info("ApiRateLimitFilter client request with clientId: " + clientId); + this.rateLimitClientRequest(clientId, today); } - - } else { - LOG.info("ApiRateLimitFilter client request with clientId: " + clientId); - this.rateLimitClientRequest(clientId, today); + } catch (Exception ex) { + LOG.error("PAPI Limit filter logic cannot be applied because of an exception. Continuing with normal flow.", ex); } - - filterChain.doFilter(httpServletRequest, httpServletResponse); } + + filterChain.doFilter(httpServletRequest, httpServletResponse); } private void rateLimitAnonymousRequest(String ipAddress, LocalDate today, HttpServletResponse httpServletResponse) throws IOException {