You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@baremaps.apache.org by bc...@apache.org on 2023/07/30 18:05:24 UTC

[incubator-baremaps] branch main updated: Remove stacktrace from response entiy and log exceptions (#728)

This is an automated email from the ASF dual-hosted git repository.

bchapuis pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git


The following commit(s) were added to refs/heads/main by this push:
     new 5e1fd3b3 Remove stacktrace from response entiy and log exceptions (#728)
5e1fd3b3 is described below

commit 5e1fd3b3349e461bc794bf01b9a5ef55697c7112
Author: Perdjesk <Pe...@users.noreply.github.com>
AuthorDate: Sun Jul 30 20:05:19 2023 +0200

    Remove stacktrace from response entiy and log exceptions (#728)
---
 .../java/org/apache/baremaps/server/GeocoderResource.java | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/baremaps-server/src/main/java/org/apache/baremaps/server/GeocoderResource.java b/baremaps-server/src/main/java/org/apache/baremaps/server/GeocoderResource.java
index 75b237d5..86f76aeb 100644
--- a/baremaps-server/src/main/java/org/apache/baremaps/server/GeocoderResource.java
+++ b/baremaps-server/src/main/java/org/apache/baremaps/server/GeocoderResource.java
@@ -33,6 +33,8 @@ import org.apache.baremaps.geocoder.GeonamesQueryBuilder;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.ScoreDoc;
 import org.apache.lucene.search.SearcherManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A resource that provides access to the geocoder.
@@ -41,6 +43,8 @@ import org.apache.lucene.search.SearcherManager;
 @javax.ws.rs.Path("/")
 public class GeocoderResource {
 
+  private static final Logger logger = LoggerFactory.getLogger(GeocoderResource.class);
+
   record GeocoderResponse(List<GeocoderResult> results) {
   }
 
@@ -85,16 +89,17 @@ public class GeocoderResource {
         return Response.status(Response.Status.OK).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
             .header(CONTENT_TYPE, APPLICATION_JSON).entity(new GeocoderResponse(results)).build();
       } catch (IllegalArgumentException e) {
-        return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
+        logger.warn("Illegal input while processing request", e);
+        return Response.status(Response.Status.BAD_REQUEST).build();
       } catch (IOException | ParseException e) {
-        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage())
-            .build();
+        logger.error("Error while processing request", e);
+        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
       } finally {
         searcherManager.release(searcher);
       }
     } catch (IOException e) {
-      return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage())
-          .build();
+      logger.error("Error while processing request", e);
+      return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
     }
   }