You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cs...@apache.org on 2022/06/03 15:03:49 UTC
[sling-org-apache-sling-distribution-core] branch master updated: SLING-11366: Provide more exception error context on the JSON API responses (#59)
This is an automated email from the ASF dual-hosted git repository.
cschneider pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-core.git
The following commit(s) were added to refs/heads/master by this push:
new a1ff2f89 SLING-11366: Provide more exception error context on the JSON API responses (#59)
a1ff2f89 is described below
commit a1ff2f8924d88949523230019c6921f74cb7a7ce
Author: José Correia <37...@users.noreply.github.com>
AuthorDate: Fri Jun 3 17:03:45 2022 +0200
SLING-11366: Provide more exception error context on the JSON API responses (#59)
* SLING-11366: Provide more exception error context on the JSON API responses
* SLING-11366: Provide more exception error context on the JSON API responses
* SLING-11366: Provide more exception error context on the JSON API responses
Co-authored-by: josec <jo...@adobe.com>
---
.../sling/distribution/servlet/DistributionAgentServlet.java | 4 +++-
.../servlet/DistributionPackageImporterServlet.java | 10 +++++++---
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/apache/sling/distribution/servlet/DistributionAgentServlet.java b/src/main/java/org/apache/sling/distribution/servlet/DistributionAgentServlet.java
index 98acf360..54df02cd 100644
--- a/src/main/java/org/apache/sling/distribution/servlet/DistributionAgentServlet.java
+++ b/src/main/java/org/apache/sling/distribution/servlet/DistributionAgentServlet.java
@@ -21,6 +21,8 @@ package org.apache.sling.distribution.servlet;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
@@ -71,7 +73,7 @@ public class DistributionAgentServlet extends SlingAllMethodsServlet {
log.debug("distribution response : {}", distributionResponse);
} catch (Throwable e) {
log.error("an unexpected error has occurred", e);
- ServletJsonUtils.writeJson(response, 503, "an unexpected error has occurred", null);
+ ServletJsonUtils.writeJson(response, 503, e.getMessage(), null);
}
} else {
ServletJsonUtils.writeJson(response, 404, "agent not found", null);
diff --git a/src/main/java/org/apache/sling/distribution/servlet/DistributionPackageImporterServlet.java b/src/main/java/org/apache/sling/distribution/servlet/DistributionPackageImporterServlet.java
index dad37def..4f2aedfc 100644
--- a/src/main/java/org/apache/sling/distribution/servlet/DistributionPackageImporterServlet.java
+++ b/src/main/java/org/apache/sling/distribution/servlet/DistributionPackageImporterServlet.java
@@ -18,6 +18,7 @@
*/
package org.apache.sling.distribution.servlet;
+import static java.lang.String.format;
import static javax.servlet.http.HttpServletResponse.*;
import static org.apache.sling.distribution.util.impl.DigestUtils.openDigestInputStream;
import static org.apache.sling.distribution.util.impl.DigestUtils.readDigestMessage;
@@ -112,7 +113,7 @@ public class DistributionPackageImporterServlet extends SlingAllMethodsServlet {
String receivedDigestMessage = readDigestMessage((DigestInputStream) stream);
if (!digestMessage.equalsIgnoreCase(receivedDigestMessage)) {
log.error("Error during distribution import: received distribution package is corrupted, expected [{}] but received [{}]",
- digestMessage, receivedDigestMessage);
+ digestMessage, receivedDigestMessage);
Map<String, String> kv = new HashMap<String, String>();
kv.put("digestAlgorithm", digestAlgorithm);
kv.put("expected", digestMessage);
@@ -126,8 +127,11 @@ public class DistributionPackageImporterServlet extends SlingAllMethodsServlet {
ServletJsonUtils.writeJson(response, SC_OK, "package imported successfully", null);
} catch (final Throwable e) {
- ServletJsonUtils.writeJson(response, SC_INTERNAL_SERVER_ERROR, "an unexpected error has occurred during distribution import", null);
- log.error("Error during distribution import", e);
+ String msg = format("an unexpected error has occurred during distribution import. " +
+ "Error: %s",
+ e.getMessage());
+ log.error(msg, e);
+ ServletJsonUtils.writeJson(response, SC_INTERNAL_SERVER_ERROR, msg, null);
} finally {
long end = System.currentTimeMillis();
log.debug("Processed package import request in {} ms", end - start);