com.adobe.platform.operation.exception.ServiceUsageException Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2019 Adobe
* All Rights Reserved.
*
* NOTICE: Adobe permits you to use, modify, and distribute this file in
* accordance with the terms of the Adobe license agreement accompanying
* it. If you have received this file from a source other than Adobe,
* then your use, modification, or distribution of it requires the prior
* written permission of Adobe.
*/
package com.adobe.platform.operation.exception;
/**
* ServiceUsageException is thrown when either Service usage limit has been reached or credentials quota has been exhausted.
*
* @see SdkException
* @see ServiceApiException
*/
public class ServiceUsageException extends RuntimeException {
/**
* the default value of status code if there is no status code for this service failure.
*/
public final int DEFAULT_STATUS_CODE = 429;
private String requestTrackingId;
private int statusCode;
/**
* Constructs a {@code ServiceUsageException} with the specified detail message.
*
* @param message the detail message
*/
public ServiceUsageException(String message) {
super(message);
this.statusCode = DEFAULT_STATUS_CODE;
}
/**
* Constructs a {@code ServiceUsageException} with the specified detail message, requestId and returned HTTP status code.
*
* @param message the detail message
* @param requestTrackingId X-Request-Id header value to track the request
* @param statusCode HTTP Status code returned in API response
*/
public ServiceUsageException(String message, String requestTrackingId, int statusCode) {
super(message);
this.requestTrackingId = requestTrackingId;
this.statusCode = statusCode;
}
/**
* Returns the detailed message for this exception.
*
* @return the detailed message
*/
@Override
public String getMessage() {
return String.format("description ='%s'; requestTrackingId='%s'; statusCode=%d",
super.getMessage(), this.getRequestTrackingId(), this.getStatusCode());
}
/**
* Returns the Request ID (the value of the X-Request-ID header).
*
* @return Request ID
*/
public String getRequestTrackingId() {
return requestTrackingId;
}
/**
* Returns the HTTP Status code or {@code DEFAULT_STATUS_CODE} if the status code doesn't adequately represent the error.
*
* @return the HTTP Status code or {@code DEFAULT_STATUS_CODE} if the status code doesn't adequately represent the error.
*/
public int getStatusCode() {
return statusCode;
}
}