-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added HTTP error details provider, refactored HTTP-sink and source pa…
…ckage to handle error provider, fix sonar issues and added Validation error for linear retry duration
- Loading branch information
1 parent
89c2ece
commit bdafbf1
Showing
19 changed files
with
549 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/main/java/io/cdap/plugin/http/common/HttpErrorDetailsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright © 2025 Cask Data, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package io.cdap.plugin.http.common; | ||
|
||
import com.google.common.base.Throwables; | ||
import io.cdap.cdap.api.exception.ErrorCategory; | ||
import io.cdap.cdap.api.exception.ErrorType; | ||
import io.cdap.cdap.api.exception.ErrorUtils; | ||
import io.cdap.cdap.api.exception.ProgramFailureException; | ||
import io.cdap.cdap.etl.api.exception.ErrorContext; | ||
import io.cdap.cdap.etl.api.exception.ErrorDetailsProvider; | ||
import io.cdap.cdap.etl.api.validation.InvalidConfigPropertyException; | ||
|
||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
|
||
/** | ||
* Error details provided for the HTTP | ||
**/ | ||
public class HttpErrorDetailsProvider implements ErrorDetailsProvider { | ||
|
||
/** | ||
* Supported document URL. | ||
*/ | ||
private static final String SUPPORTED_DOCUMENT_URL = "https://datatracker.ietf.org/doc/html/rfc7231#section-6"; | ||
|
||
/** | ||
* Retrieves the supported document URL. | ||
* | ||
* @return the supported document URL | ||
*/ | ||
public static String getSupportedDocumentUrl() { | ||
return SUPPORTED_DOCUMENT_URL; | ||
} | ||
|
||
@Override | ||
public ProgramFailureException getExceptionDetails(Exception e, ErrorContext errorContext) { | ||
List<Throwable> causalChain = Throwables.getCausalChain(e); | ||
for (Throwable t : causalChain) { | ||
if (t instanceof ProgramFailureException) { | ||
// if causal chain already has program failure exception, return null to avoid double wrap. | ||
return null; | ||
} | ||
if (t instanceof IllegalArgumentException) { | ||
return getProgramFailureException((IllegalArgumentException) t, errorContext, | ||
ErrorType.USER); | ||
} | ||
if (t instanceof IllegalStateException) { | ||
return getProgramFailureException((IllegalStateException) t, errorContext, | ||
ErrorType.SYSTEM); | ||
} | ||
if (t instanceof InvalidConfigPropertyException) { | ||
return getProgramFailureException((InvalidConfigPropertyException) t, errorContext, | ||
ErrorType.USER); | ||
} | ||
if (t instanceof NoSuchElementException) { | ||
return getProgramFailureException((NoSuchElementException) t, errorContext, | ||
ErrorType.SYSTEM); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Get a ProgramFailureException with the given error information from {@link Exception}. | ||
* | ||
* @param exception The IllegalArgumentException to get the error information from. | ||
* @return A ProgramFailureException with the given error information. | ||
*/ | ||
private ProgramFailureException getProgramFailureException(Exception exception, | ||
ErrorContext errorContext, ErrorType errorType) { | ||
String errorMessage = exception.getMessage(); | ||
String errorMessageFormat = "Error occurred in the phase: '%s'. Error message: %s"; | ||
return ErrorUtils.getProgramFailureException( | ||
new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorMessage, | ||
String.format(errorMessageFormat, errorContext.getPhase(), errorMessage), errorType, false, | ||
exception); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.