Skip to content

Commit

Permalink
Have FlowFrameworkException status recognized by ExceptionsHelper
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Jul 26, 2024
1 parent 034dff7 commit 3936f0b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}

Check warning on line 70 in src/main/java/org/opensearch/flowframework/exception/FlowFrameworkException.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/exception/FlowFrameworkException.java#L68-L70

Added lines #L68 - L70 were not covered by tests

/**
* Getter for restStatus.
*
Expand All @@ -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);
}

Check warning on line 96 in src/main/java/org/opensearch/flowframework/exception/FlowFrameworkException.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/exception/FlowFrameworkException.java#L94-L96

Added lines #L94 - L96 were not covered by tests

// Keeping toXContentObject for backwards compatibility but this is needed for overriding superclass fragment
@Override
public boolean isFragment() {
return false;

Check warning on line 101 in src/main/java/org/opensearch/flowframework/exception/FlowFrameworkException.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/exception/FlowFrameworkException.java#L101

Added line #L101 was not covered by tests
}
}

0 comments on commit 3936f0b

Please sign in to comment.