-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab865c5
commit b6ef011
Showing
25 changed files
with
425 additions
and
264 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
35 changes: 0 additions & 35 deletions
35
src/main/java/io/cdap/plugin/servicenow/apiclient/NonRetryableException.java
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
src/main/java/io/cdap/plugin/servicenow/apiclient/RetryableException.java
This file was deleted.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
src/main/java/io/cdap/plugin/servicenow/apiclient/ServiceNowAPIException.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,79 @@ | ||
package io.cdap.plugin.servicenow.apiclient; | ||
|
||
import io.cdap.plugin.servicenow.util.ServiceNowConstants; | ||
|
||
import org.apache.http.HttpResponse; | ||
import org.apache.http.HttpStatus; | ||
import org.apache.oltu.oauth2.common.exception.OAuthSystemException; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Custom Exception class for propagating API errors/exceptions back to caller. | ||
*/ | ||
public class ServiceNowAPIException extends Exception { | ||
|
||
@Nullable private final HttpResponse httpResponse; | ||
private final int statusCode; | ||
|
||
private static final Set<Integer> RETRYABLE_CODES = new HashSet<>(Arrays.asList(429, | ||
HttpStatus.SC_BAD_GATEWAY, | ||
HttpStatus.SC_SERVICE_UNAVAILABLE, | ||
HttpStatus.SC_REQUEST_TIMEOUT, | ||
HttpStatus.SC_GATEWAY_TIMEOUT)); | ||
// private final boolean isErrorRetryable; | ||
|
||
public ServiceNowAPIException( | ||
String message, Throwable t, @Nullable HttpResponse httpResponse, int statusCode) { | ||
super(message, t); | ||
this.httpResponse = httpResponse; | ||
this.statusCode = statusCode; | ||
} | ||
|
||
public ServiceNowAPIException( | ||
Throwable t, @Nullable HttpResponse httpResponse, int statusCode) { | ||
super(t); | ||
this.httpResponse = httpResponse; | ||
this.statusCode = statusCode; | ||
} | ||
|
||
public ServiceNowAPIException(String message, Throwable t) { | ||
this(message, t, null, 0); | ||
} | ||
|
||
public ServiceNowAPIException( | ||
Throwable t, @Nullable HttpResponse httpResponse) { | ||
this(t, httpResponse, 0); | ||
} | ||
|
||
public ServiceNowAPIException( | ||
String message, @Nullable HttpResponse httpResponse) { | ||
this(message, httpResponse, 0); | ||
} | ||
|
||
public ServiceNowAPIException( | ||
String message, @Nullable HttpResponse httpResponse, int statusCode) { | ||
super(message); | ||
this.httpResponse = httpResponse; | ||
this.statusCode = statusCode; | ||
} | ||
|
||
public HttpResponse getHttpResponse() { | ||
return httpResponse; | ||
} | ||
|
||
public int getStatusCode() { | ||
return statusCode; | ||
} | ||
|
||
public boolean isErrorRetryable() { | ||
Throwable t = this.getCause(); | ||
return t instanceof OAuthSystemException | ||
|| (this.getMessage() != null | ||
&& this.getMessage().contains(ServiceNowConstants.MAXIMUM_EXECUTION_TIME_EXCEEDED)) | ||
|| RETRYABLE_CODES.contains(statusCode); | ||
} | ||
} |
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.