From ec6385766e0b1f868e58aa689318aabf70e18bdd Mon Sep 17 00:00:00 2001 From: Shinsuke Sugaya Date: Thu, 15 Aug 2024 17:29:04 +0900 Subject: [PATCH] fix #2839 Adjust API response to conditionally include exception messages based on configuration. --- .../fess/api/engine/SearchEngineApiManager.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/codelibs/fess/api/engine/SearchEngineApiManager.java b/src/main/java/org/codelibs/fess/api/engine/SearchEngineApiManager.java index bc33b9bf9..02843bd3e 100644 --- a/src/main/java/org/codelibs/fess/api/engine/SearchEngineApiManager.java +++ b/src/main/java/org/codelibs/fess/api/engine/SearchEngineApiManager.java @@ -102,8 +102,16 @@ public void process(final HttpServletRequest request, final HttpServletResponse throw new WebApiException(HttpServletResponse.SC_FORBIDDEN, "Invalid session."); }); } catch (final WebApiException e) { - logger.debug("Failed to access to Web API.", e); - response.sendError(e.getStatusCode(), e.getMessage()); + String message; + if (Constants.TRUE.equalsIgnoreCase(ComponentUtil.getFessConfig().getApiJsonResponseExceptionIncluded())) { + logger.warn("Failed to access to Web API.", e); + message = e.getMessage(); + } else { + final String errorCode = UUID.randomUUID().toString(); + message = "[" + errorCode + "] Failed to access to Web API."; + logger.warn(message, e); + } + response.sendError(e.getStatusCode(), message); } }