From 3936f0bb2c2595ebf2ca00df27bcb396bf36b379 Mon Sep 17 00:00:00 2001 From: Daniel Widdis Date: Thu, 25 Jul 2024 23:27:23 -0700 Subject: [PATCH] Have FlowFrameworkException status recognized by ExceptionsHelper Signed-off-by: Daniel Widdis --- CHANGELOG.md | 1 + ...h-flow-framework.release-notes-2.16.0.0.md | 1 + .../exception/FlowFrameworkException.java | 33 ++++++++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37f8cb28d..67442bc6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) ### Bug Fixes - Handle Not Found exceptions as successful deletions for agents and models ([#805](https://github.com/opensearch-project/flow-framework/pull/805)) +- Have FlowFrameworkException status recognized by ExceptionsHelper ([#811](https://github.com/opensearch-project/flow-framework/pull/811)) ### Infrastructure ### Documentation diff --git a/release-notes/opensearch-flow-framework.release-notes-2.16.0.0.md b/release-notes/opensearch-flow-framework.release-notes-2.16.0.0.md index 79e0bd9e3..aba284e55 100644 --- a/release-notes/opensearch-flow-framework.release-notes-2.16.0.0.md +++ b/release-notes/opensearch-flow-framework.release-notes-2.16.0.0.md @@ -10,6 +10,7 @@ Compatible with OpenSearch 2.16.0 ### Bug Fixes - Handle Not Found deprovision exceptions as successful deletions ([#805](https://github.com/opensearch-project/flow-framework/pull/805)) +- Have FlowFrameworkException status recognized by ExceptionsHelper ([#811](https://github.com/opensearch-project/flow-framework/pull/811)) ### Infrastructure - Update dependency com.fasterxml.jackson.core:jackson-core to v2.17.2 ([#760](https://github.com/opensearch-project/flow-framework/pull/760)) diff --git a/src/main/java/org/opensearch/flowframework/exception/FlowFrameworkException.java b/src/main/java/org/opensearch/flowframework/exception/FlowFrameworkException.java index 8d8ec4850..1373b54ca 100644 --- a/src/main/java/org/opensearch/flowframework/exception/FlowFrameworkException.java +++ b/src/main/java/org/opensearch/flowframework/exception/FlowFrameworkException.java @@ -8,6 +8,9 @@ */ package org.opensearch.flowframework.exception; +import org.opensearch.OpenSearchException; +import org.opensearch.core.common.io.stream.StreamInput; +import org.opensearch.core.common.io.stream.StreamOutput; import org.opensearch.core.rest.RestStatus; import org.opensearch.core.xcontent.ToXContentObject; import org.opensearch.core.xcontent.XContentBuilder; @@ -17,7 +20,7 @@ /** * Representation of Flow Framework Exceptions */ -public class FlowFrameworkException extends RuntimeException implements ToXContentObject { +public class FlowFrameworkException extends OpenSearchException implements ToXContentObject { private static final long serialVersionUID = 1L; @@ -56,6 +59,16 @@ public FlowFrameworkException(String message, Throwable cause, RestStatus restSt this.restStatus = restStatus; } + /** + * Read from a stream. + * @param in THe input stream + * @throws IOException on stream reading failure + */ + public FlowFrameworkException(StreamInput in) throws IOException { + super(in); + restStatus = RestStatus.readFrom(in); + } + /** * Getter for restStatus. * @@ -65,8 +78,26 @@ public RestStatus getRestStatus() { return restStatus; } + // Same getter but for superclass + @Override + public final RestStatus status() { + return restStatus; + } + @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { return builder.startObject().field("error", this.getMessage()).endObject(); } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + RestStatus.writeTo(out, restStatus); + } + + // Keeping toXContentObject for backwards compatibility but this is needed for overriding superclass fragment + @Override + public boolean isFragment() { + return false; + } }