diff --git a/cdap-api-common/src/main/java/io/cdap/cdap/api/exception/ProgramFailureException.java b/cdap-api-common/src/main/java/io/cdap/cdap/api/exception/ProgramFailureException.java index e8fce1fa894..6d48de3e7e2 100644 --- a/cdap-api-common/src/main/java/io/cdap/cdap/api/exception/ProgramFailureException.java +++ b/cdap-api-common/src/main/java/io/cdap/cdap/api/exception/ProgramFailureException.java @@ -34,20 +34,24 @@ * such as SYSTEM, USER, or UNKNOWN. *
  • cause: The cause of this throwable or null if the cause is nonexistent * or unknown.
  • + *
  • dependency: A boolean value indicating whether the error is coming from a + * dependent service.
  • * **/ public class ProgramFailureException extends RuntimeException { private final ErrorCategory errorCategory; private final String errorReason; private final ErrorType errorType; + private final boolean dependency; // Private constructor to prevent direct instantiation - private ProgramFailureException(ErrorCategory errorCategory, String errorMessage, String errorReason, - ErrorType errorType, Throwable cause) { + private ProgramFailureException(ErrorCategory errorCategory, String errorMessage, + String errorReason, ErrorType errorType, Throwable cause, boolean dependency) { super(errorMessage, cause); this.errorCategory = errorCategory; this.errorReason = errorReason; this.errorType = errorType; + this.dependency = dependency; } /** @@ -87,6 +91,15 @@ public ErrorType getErrorType() { return errorType == null ? ErrorType.UNKNOWN : errorType; } + /** + * Returns whether the error is coming from a dependent service. + * + * @return true if the error is a dependency service error, false otherwise. + */ + public boolean isDependency() { + return dependency; + } + /** * Builder class for ProgramFailureException. */ @@ -96,6 +109,7 @@ public static class Builder { private String errorReason; private ErrorType errorType; private Throwable cause; + private boolean dependency; /** * Sets the error category for the ProgramFailureException. @@ -152,6 +166,11 @@ public Builder withCause(Throwable cause) { return this; } + public Builder withDependency(boolean dependency) { + this.dependency = dependency; + return this; + } + /** * Builds and returns a new instance of ProgramFailureException. * @@ -159,7 +178,7 @@ public Builder withCause(Throwable cause) { */ public ProgramFailureException build() { return new ProgramFailureException(errorCategory, errorMessage, - errorReason, errorType, cause); + errorReason, errorType, cause, dependency); } } }