@@ -70,6 +70,7 @@ public class PipesParsingHelper {
7070 private final PipesConfig pipesConfig ;
7171 private final Path inputTempDirectory ;
7272 private final Path unpackEmitterBasePath ;
73+ private final boolean returnStackTrace ;
7374
7475 /**
7576 * Creates a PipesParsingHelper.
@@ -81,13 +82,19 @@ public class PipesParsingHelper {
8182 * @param unpackEmitterBasePath the basePath where the unpack-emitter writes files.
8283 * This is where the server will find the zip files created
8384 * by UNPACK mode. May be null if UNPACK mode won't be used.
85+ * @param returnStackTrace whether failure responses may include the (potentially
86+ * stack-trace-bearing) {@code PipesResult} message. When false
87+ * (the default), error bodies carry only the status. Mirrors
88+ * {@code TikaServerConfig.isReturnStackTrace()}.
8489 */
8590 public PipesParsingHelper (PipesParser pipesParser , PipesConfig pipesConfig ,
86- Path inputTempDirectory , Path unpackEmitterBasePath ) {
91+ Path inputTempDirectory , Path unpackEmitterBasePath ,
92+ boolean returnStackTrace ) {
8793 this .pipesParser = pipesParser ;
8894 this .pipesConfig = pipesConfig ;
8995 this .inputTempDirectory = inputTempDirectory ;
9096 this .unpackEmitterBasePath = unpackEmitterBasePath ;
97+ this .returnStackTrace = returnStackTrace ;
9198
9299 if (inputTempDirectory == null || !Files .isDirectory (inputTempDirectory )) {
93100 throw new IllegalArgumentException (
@@ -189,18 +196,21 @@ private String getSuffix(Metadata metadata) {
189196
190197 /**
191198 * Builds a JSON error response carrying a subset of the {@code PipesResult}
192- * serialization — the {@code status} and, when present, a non-blank {@code message}:
193- * {@code {"status": "TIMEOUT", "message": "..."}}. Successful-parse fields such as
194- * {@code emitData} are never part of an error body.
199+ * serialization. By default the body is just {@code {"status": "TIMEOUT"}}. The
200+ * {@code PipesResult} message frequently contains a server-side stack trace
201+ * (e.g. for {@code *_EXCEPTION} statuses), so the {@code message} field is included
202+ * only when {@code returnStackTrace} is enabled — matching the legacy
203+ * {@code TikaServerParseExceptionMapper}, which gates stack traces the same way.
204+ * Successful-parse fields such as {@code emitData} are never part of an error body.
195205 * <p>
196206 * This allows clients to distinguish failure modes (TIMEOUT, OOM, UNSPECIFIED_CRASH, …)
197207 * without parsing plain-text bodies or inspecting custom headers.
198208 */
199- private static Response buildProcessFailureResponse (PipesResult result ) {
209+ private Response buildProcessFailureResponse (PipesResult result ) {
200210 ObjectMapper mapper = new ObjectMapper ();
201211 ObjectNode node = mapper .createObjectNode ();
202212 node .put ("status" , result .status ().name ());
203- if (result .message () != null && !result .message ().isBlank ()) {
213+ if (returnStackTrace && result .message () != null && !result .message ().isBlank ()) {
204214 node .put ("message" , result .message ());
205215 }
206216 String json ;
0 commit comments