|
| 1 | +/* |
| 2 | + * Copyright OpenSearch Contributors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + * |
| 5 | + * The OpenSearch Contributors require contributions made to |
| 6 | + * this file be licensed under the Apache-2.0 license or a |
| 7 | + * compatible open source license. |
| 8 | + */ |
| 9 | +package org.opensearch.flowframework.exception; |
| 10 | + |
| 11 | +import org.opensearch.core.rest.RestStatus; |
| 12 | +import org.opensearch.core.xcontent.ToXContentObject; |
| 13 | +import org.opensearch.core.xcontent.XContentBuilder; |
| 14 | + |
| 15 | +import java.io.IOException; |
| 16 | + |
| 17 | +/** |
| 18 | + * Representation of an exception that is caused by a workflow step failing outside of our plugin |
| 19 | + * This is caught by an external client (e.g. ml-client) returning the failure |
| 20 | + */ |
| 21 | +public class WorkflowStepException extends FlowFrameworkException implements ToXContentObject { |
| 22 | + |
| 23 | + private static final long serialVersionUID = 1L; |
| 24 | + |
| 25 | + /** |
| 26 | + * Constructor with error message. |
| 27 | + * |
| 28 | + * @param message message of the exception |
| 29 | + * @param restStatus HTTP status code of the response |
| 30 | + */ |
| 31 | + public WorkflowStepException(String message, RestStatus restStatus) { |
| 32 | + super(message, restStatus); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Constructor with specified cause. |
| 37 | + * @param cause exception cause |
| 38 | + * @param restStatus HTTP status code of the response |
| 39 | + */ |
| 40 | + public WorkflowStepException(Throwable cause, RestStatus restStatus) { |
| 41 | + super(cause, restStatus); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Constructor with specified error message adn cause. |
| 46 | + * @param message error message |
| 47 | + * @param cause exception cause |
| 48 | + * @param restStatus HTTP status code of the response |
| 49 | + */ |
| 50 | + public WorkflowStepException(String message, Throwable cause, RestStatus restStatus) { |
| 51 | + super(message, cause, restStatus); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Getter for restStatus. |
| 56 | + * |
| 57 | + * @return the HTTP status code associated with the exception |
| 58 | + */ |
| 59 | + public RestStatus getRestStatus() { |
| 60 | + return restStatus; |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { |
| 65 | + return builder.startObject().field("error", this.getMessage()).endObject(); |
| 66 | + } |
| 67 | +} |
0 commit comments