null
if the exception was thrown before creating a request.
- */
- private final RestRequestInformation request;
-
- /**
- * The rest request result. May be null
if the exception was thrown before sending a request.
- */
- private final RestRequestResponseInformation response;
-
- /**
- * Creates a new instance of this class.
- *
- * @param origin The origin of the exception.
- * @param message The message of the exception.
- * @param request The information about the request.
- * @param response The information about the response.
- */
- public AzureException(Exception origin, String message, RestRequestInformation request,
- RestRequestResponseInformation response) {
- super(message, origin);
- this.request = request;
- this.response = response;
- }
-
- /**
- * Gets information about the request which caused the exception.
- * May be null
if the exception was thrown before creating a request.
- *
- * @return Information about the request which caused the exception.
- */
- public Optionalnull
if the exception was thrown before creating a request.
+ */
+ private final RestRequestInformation request;
+
+ /**
+ * The rest request result. May be null
if the exception was thrown before sending a
+ * request.
+ */
+ private final RestRequestResponseInformation response;
+
+ /**
+ * Creates a new instance of this class.
+ *
+ * @param origin The origin of the exception.
+ * @param message The message of the exception.
+ * @param request The information about the request.
+ * @param response The information about the response.
+ */
+ public AzureException(
+ Exception origin,
+ String message,
+ RestRequestInformation request,
+ RestRequestResponseInformation response) {
+ super(message, origin);
+ this.request = request;
+ this.response = response;
+ }
+
+ /**
+ * Gets information about the request which caused the exception. May be null
if the
+ * exception was thrown before creating a request.
+ *
+ * @return Information about the request which caused the exception.
+ */
+ public OptionalTo compensate for misalignment with the real global ratelimit bucket, it is recommended to not set the value - * to the exact global ratelimit but a lower value. If the global ratelimit for your bot is 50 requests / 1 second - * (the default), you should choose a value that prevents overlapping with the real bucket. This can be achieved with - * the following rules: + *
To compensate for misalignment with the real global ratelimit bucket, it is recommended to not + * set the value to the exact global ratelimit but a lower value. If the global ratelimit for your + * bot is 50 requests / 1 second (the default), you should choose a value that prevents overlapping + * with the real bucket. This can be achieved with the following rules: + * *
Use {@link System#nanoTime()} to calculate the absolute difference. - * - * @return The next time the quota resets. Can be in the past. - */ - public long getNextResetNanos() { - return nextResetNanos; - } - - /** - * Gets the remaining quota in the current reset interval. - * - * @return The remaining quota. - */ - public int getRemainingQuota() { - return remainingQuota; - } + /** + * Gets the next time the quota resets. + * + *
Use {@link System#nanoTime()} to calculate the absolute difference.
+ *
+ * @return The next time the quota resets. Can be in the past.
+ */
+ public long getNextResetNanos() {
+ return nextResetNanos;
+ }
- @Override
- public synchronized void requestQuota() throws InterruptedException {
- if (remainingQuota <= 0) {
- // Wait until a new quota becomes available
- long sleepTime;
- while ((sleepTime = calculateSleepTime()) > 0) { // Sleep is unreliable, so we have to loop
- Thread.sleep(sleepTime / 1_000_000, (int) (sleepTime % 1_000_000));
- }
- }
+ /**
+ * Gets the remaining quota in the current reset interval.
+ *
+ * @return The remaining quota.
+ */
+ public int getRemainingQuota() {
+ return remainingQuota;
+ }
- // Reset the limit when the last reset timestamp is past
- if (System.nanoTime() >= nextResetNanos) {
- remainingQuota = amount;
- try {
- nextResetNanos = System.nanoTime() + bucketDuration.toNanos();
- } catch (ArithmeticException e) {
- // An ArithmeticException means that the duration was too large to be represented
- // as a long. While such a value is completely non-sense and should not be used, we
- // still don't want an exception.
- nextResetNanos = Long.MAX_VALUE;
- }
- }
-
- remainingQuota--;
+ @Override
+ public synchronized void requestQuota() throws InterruptedException {
+ if (remainingQuota <= 0) {
+ // Wait until a new quota becomes available
+ long sleepTime;
+ while ((sleepTime = calculateSleepTime()) > 0) { // Sleep is unreliable, so we have to loop
+ Thread.sleep(sleepTime / 1_000_000, (int) (sleepTime % 1_000_000));
+ }
}
- private long calculateSleepTime() {
- return nextResetNanos - System.nanoTime();
+ // Reset the limit when the last reset timestamp is past
+ if (System.nanoTime() >= nextResetNanos) {
+ remainingQuota = amount;
+ try {
+ nextResetNanos = System.nanoTime() + bucketDuration.toNanos();
+ } catch (ArithmeticException e) {
+ // An ArithmeticException means that the duration was too large to be represented
+ // as a long. While such a value is completely non-sense and should not be used, we
+ // still don't want an exception.
+ nextResetNanos = Long.MAX_VALUE;
+ }
}
-}
\ No newline at end of file
+
+ remainingQuota--;
+ }
+
+ private long calculateSleepTime() {
+ return nextResetNanos - System.nanoTime();
+ }
+}
diff --git a/src/main/java/tech/brenoepic/at4j/core/ratelimit/RateLimitManager.java b/src/main/java/tech/brenoepic/at4j/core/ratelimit/RateLimitManager.java
index 1166228..728abbe 100644
--- a/src/main/java/tech/brenoepic/at4j/core/ratelimit/RateLimitManager.java
+++ b/src/main/java/tech/brenoepic/at4j/core/ratelimit/RateLimitManager.java
@@ -1,5 +1,10 @@
package tech.brenoepic.at4j.core.ratelimit;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
import okhttp3.Response;
import org.apache.logging.log4j.Logger;
import tech.brenoepic.at4j.core.AzureApiImpl;
@@ -9,206 +14,217 @@
import tech.brenoepic.at4j.util.rest.RestRequestResponseInformationImpl;
import tech.brenoepic.at4j.util.rest.RestRequestResult;
-import java.util.HashSet;
-import java.util.Objects;
-import java.util.Set;
-import java.util.concurrent.CompletableFuture;
-import java.util.function.Function;
-
-/**
- * This class manages rate-limits and keeps track of them.
- */
+/** This class manages rate-limits and keeps track of them. */
public class RateLimitManager {
- /**
- * The (logger) of this class.
- */
- private static final Logger logger = LoggerUtil.getLogger(RateLimitManager.class);
-
- /**
- * The Azure API instance for this rate-limit manager.
- */
- private final AzureApiImpl api;
-
- /**
- * All buckets.
- */
- private final Set This allows you to get a fresh executor service when calling {@link #getSingleThreadExecutorService(String)}
- * again.
- *
- * @param threadName The thread name of the executor service.
- * @return The removed and shutdown executor service with the given thread name.
- */
- Optional This allows you to get a fresh executor service when calling {@link
+ * #getSingleThreadExecutorService(String)} again.
+ *
+ * @param threadName The thread name of the executor service.
+ * @return The removed and shutdown executor service with the given thread name.
+ */
+ Optional Tasks will be scheduled on the daemon executor, allowing the bot to shutdown without
- * all tasks being executed. This method is not meant to persist scheduled task over
- * multiple bot life cycles. Tasks will be scheduled on the daemon executor, allowing the bot to shutdown without all
+ * tasks being executed. This method is not meant to persist scheduled task over multiple bot life
+ * cycles.
+ *
+ * @param task The code to run.
+ * @param duration The duration to run the code after.
+ * @param unit The unit of the duration given.
+ * @return A future that completes when the scheduled task is finished.
+ * @param
- * Language autodetection is applied when the from parameter is omitted. If detection fails, the `suggestedFrom` language is assumed
- * @param suggestedFromLanguage A string representing the language code of the translation text.
- * @return This instance.
- */
- public TranslateParams setSuggestedFromLanguage(String suggestedFromLanguage) {
- this.suggestedFromLanguage = suggestedFromLanguage;
- return this;
+ private String text;
+ private TextType textType;
+ private ProfanityAction profanityAction;
+ private ProfanityMarker profanityMarker;
+ private Boolean includeAlignment;
+ private Boolean includeSentenceLength;
+ private String sourceLanguage;
+ private Collection
+ * Language autodetection is applied when the from parameter is omitted. If detection fails, the
+ * `suggestedFrom` language is assumed
+ *
+ * @param suggestedFromLanguage A string representing the language code of the translation text.
+ * @return This instance.
+ */
+ public TranslateParams setSuggestedFromLanguage(String suggestedFromLanguage) {
+ this.suggestedFromLanguage = suggestedFromLanguage;
+ return this;
+ }
+
+ public TranslateParams setSourceLanguage(Language sourceLanguage) {
+ this.sourceLanguage = sourceLanguage.getCode();
+ return this;
+ }
+
+ public TranslateParams setSourceLanguage(String sourceLanguage) {
+ this.sourceLanguage = sourceLanguage;
+ return this;
+ }
+
+ public TranslateParams setTargetLanguages(Collection
- * Allowed group names are: translation, transliteration, and dictionary.
- *
- * If no scope is given, then all groups are returned, which is equivalent to passing scope=translation,transliteration,dictionary.
+ * A comma-separated list of names defining the group of languages to return.
+ * Allowed group names are: translation, transliteration, and dictionary.
+ * If no scope is given, then all groups are returned, which is equivalent to passing
+ * scope=translation,transliteration,dictionary.
*/
public enum LanguageScope {
+ TRANSLATION("translation"),
+ TRANSLITERATION("transliteration"),
+ DICTIONARY("dictionary");
- TRANSLATION("translation"),
- TRANSLITERATION("transliteration"),
- DICTIONARY("dictionary");
+ private final String value;
- private final String value;
- LanguageScope(String value) {
- this.value = value;
- }
-
- public String getValue() {
- return value;
- }
+ LanguageScope(String value) {
+ this.value = value;
+ }
+ public String getValue() {
+ return value;
+ }
}
diff --git a/src/main/java/tech/brenoepic/at4j/data/request/optional/ProfanityAction.java b/src/main/java/tech/brenoepic/at4j/data/request/optional/ProfanityAction.java
index 19b78e9..c02514a 100644
--- a/src/main/java/tech/brenoepic/at4j/data/request/optional/ProfanityAction.java
+++ b/src/main/java/tech/brenoepic/at4j/data/request/optional/ProfanityAction.java
@@ -1,22 +1,25 @@
package tech.brenoepic.at4j.data.request.optional;
/**
- * Specifies how profanities should be treated in translations.
- *
+ * Specifies how profanities should be treated in translations.
* Possible values are: Marked, Deleted or NoAction (default).
- * @see Handle profanity
+ *
+ * @see Handle
+ * profanity
*/
public enum ProfanityAction {
- MARKED("Marked"),
- DELETED("Deleted"),
- NO_ACTION("NoAction");
+ MARKED("Marked"),
+ DELETED("Deleted"),
+ NO_ACTION("NoAction");
- private final String value;
- ProfanityAction(String value) {
- this.value = value;
- }
+ private final String value;
- public String getValue() {
- return value;
- }
+ ProfanityAction(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
}
diff --git a/src/main/java/tech/brenoepic/at4j/data/request/optional/ProfanityMarker.java b/src/main/java/tech/brenoepic/at4j/data/request/optional/ProfanityMarker.java
index 3c63da8..527fe4c 100644
--- a/src/main/java/tech/brenoepic/at4j/data/request/optional/ProfanityMarker.java
+++ b/src/main/java/tech/brenoepic/at4j/data/request/optional/ProfanityMarker.java
@@ -1,20 +1,24 @@
package tech.brenoepic.at4j.data.request.optional;
/**
- * Specifies how profanities should be marked in translations.
- * Possible values are: Asterisk (default) or Tag. To understand ways to treat profanity.
- * @see Profanity Handling
+ * Specifies how profanities should be marked in translations. Possible values are: Asterisk
+ * (default) or Tag. To understand ways to treat profanity.
+ *
+ * @see Profanity
+ * Handling
*/
public enum ProfanityMarker {
- ASTERISK("Asterisk"),
- TAG("Tag");
+ ASTERISK("Asterisk"),
+ TAG("Tag");
- private final String value;
- ProfanityMarker(String value) {
- this.value = value;
- }
+ private final String value;
- public String getValue() {
- return value;
- }
+ ProfanityMarker(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
}
diff --git a/src/main/java/tech/brenoepic/at4j/data/request/optional/TextType.java b/src/main/java/tech/brenoepic/at4j/data/request/optional/TextType.java
index 575420b..4b15a68 100644
--- a/src/main/java/tech/brenoepic/at4j/data/request/optional/TextType.java
+++ b/src/main/java/tech/brenoepic/at4j/data/request/optional/TextType.java
@@ -1,19 +1,21 @@
package tech.brenoepic.at4j.data.request.optional;
+
/**
- * Defines whether the text being translated is plain text or HTML text. Any HTML needs to be a well-formed, complete element.
- *
+ * Defines whether the text being translated is plain text or HTML text. Any HTML needs to be a
+ * well-formed, complete element.
* Possible values are: plain (default) or html.
*/
public enum TextType {
- PLAIN("plain"),
- HTML("html");
+ PLAIN("plain"),
+ HTML("html");
+
+ private final String value;
- private final String value;
- TextType(String value) {
- this.value = value;
- }
+ TextType(String value) {
+ this.value = value;
+ }
- public String getValue() {
- return value;
- }
+ public String getValue() {
+ return value;
+ }
}
diff --git a/src/main/java/tech/brenoepic/at4j/data/response/TranslationResponse.java b/src/main/java/tech/brenoepic/at4j/data/response/TranslationResponse.java
index 6f2f122..18361af 100644
--- a/src/main/java/tech/brenoepic/at4j/data/response/TranslationResponse.java
+++ b/src/main/java/tech/brenoepic/at4j/data/response/TranslationResponse.java
@@ -1,36 +1,35 @@
package tech.brenoepic.at4j.data.response;
+import java.util.Collection;
+import javax.annotation.Nullable;
import tech.brenoepic.at4j.data.DetectedLanguage;
import tech.brenoepic.at4j.data.Translation;
-import javax.annotation.Nullable;
-import java.util.Collection;
-
public class TranslationResponse {
- @Nullable
- private DetectedLanguage detectedLanguage = null;
- private final Collection0
or -1
if no major
+ * parameter exists.
+ */
+ private final int majorParameterPosition;
- /**
- * The position of the major parameter starting with 0
or -1
if no major parameter exists.
- */
- private final int majorParameterPosition;
+ RestEndpoint(String endpointUrl) {
+ this(endpointUrl, -1);
+ }
- RestEndpoint(String endpointUrl) {
- this(endpointUrl, -1);
- }
+ RestEndpoint(String endpointUrl, int majorParameterPosition) {
+ this.endpointUrl = endpointUrl;
+ this.majorParameterPosition = majorParameterPosition;
+ }
- RestEndpoint(String endpointUrl, int majorParameterPosition) {
- this.endpointUrl = endpointUrl;
- this.majorParameterPosition = majorParameterPosition;
+ /**
+ * Gets the major parameter position of the endpoint. The position starts counting at 0
+ *
!
+ *
+ * @return An optional which is present if the endpoint has a major parameter.
+ */
+ public Optional0
!
- *
- * @return An optional which is present if the endpoint has a major parameter.
- */
- public Optional
- * The error code is a 6-digit number combining the 3-digit HTTP status code followed by a 3-digit number to further categorize the error.
+ * An enum with all rest request result codes as defined by Azure
+ * API Errors.
+ * The error code is a 6-digit number combining the 3-digit HTTP status code followed by a
+ * 3-digit number to further categorize the error.
*/
public enum RestRequestResultErrorCode {
+ TARGET_LANGUAGE_NOT_VALID(
+ 400036,
+ "The target language is not valid or target language field is missing",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ BODY_REQUEST_NOT_VALID_JSON(
+ 400074,
+ "The body of the request is not valid JSON.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ REQUEST_INPUT_INVALID(
+ 400000,
+ "One of the request inputs isn't valid.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ SCOPE_PARAMETER_INVALID(
+ 400001,
+ "The \"scope\" parameter is invalid.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ CATEGORY_PARAMETER_INVALID(
+ 400002,
+ "The \"category\" parameter is invalid.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ LANGUAGE_SPECIFIER_INVALID(
+ 400003,
+ "A language specifier is missing or invalid.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ TARGET_SCRIPT_SPECIFIER_INVALID(
+ 400004,
+ "A target script specifier (\"To script\") is missing or invalid.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ INPUT_TEXT_INVALID(
+ 400005,
+ "An input text is missing or invalid.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ LANGUAGE_SCRIPT_COMBINATION_INVALID(
+ 400006,
+ "The combination of language and script isn't valid.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ SOURCE_SCRIPT_SPECIFIER_INVALID(
+ 400018,
+ "A source script specifier (\"From script\") is missing or invalid.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ SPECIFIED_LANGUAGE_UNSUPPORTED(
+ 400019,
+ "One of the specified languages isn't supported.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ INPUT_TEXT_ARRAY_ELEMENT_INVALID(
+ 400020,
+ "One of the elements in the array of input text isn't valid.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ API_VERSION_PARAMETER_INVALID(
+ 400021,
+ "The API version parameter is missing or invalid.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ SPECIFIED_LANGUAGE_PAIR_INVALID(
+ 400023,
+ "One of the specified language pair isn't valid.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ SOURCE_LANGUAGE_INVALID(
+ 400035,
+ "The source language (\"From\" field) isn't valid.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ OPTIONS_FIELD_INVALID(
+ 400042,
+ "One of the options specified (\"Options\" field) isn't valid.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ CLIENT_TRACE_ID_INVALID(
+ 400043,
+ "The client trace ID (ClientTraceId field or X-ClientTranceId header) is missing or invalid.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ INPUT_TEXT_TOO_LONG(
+ 400050,
+ "The input text is too long. View request limits.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ TRANSLATION_PARAMETER_INVALID(
+ 400064,
+ "The \"translation\" parameter is missing or invalid.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ TARGET_SCRIPTS_NOT_MATCH_TARGET_LANGUAGES(
+ 400070,
+ "The number of target scripts (ToScript parameter) doesn't match the number of target"
+ + " languages (To parameter).",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ TEXT_TYPE_INVALID(
+ 400071,
+ "The value isn't valid for TextType.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ INPUT_TEXT_ARRAY_TOO_MANY_ELEMENTS(
+ 400072,
+ "The array of input text has too many elements.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ SCRIPT_PARAMETER_INVALID(
+ 400073,
+ "The script parameter isn't valid.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ LANGUAGE_PAIR_CATEGORY_COMBINATION_INVALID(
+ 400075,
+ "The language pair and category combination isn't valid.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ REQUEST_SIZE_EXCEEDED(
+ 400077,
+ "The maximum request size has been exceeded. View request limits.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ CUSTOM_SYSTEM_NOT_EXIST(
+ 400079,
+ "The custom system requested for translation between from and to language doesn't exist.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ TRANSLITERATION_NOT_SUPPORTED(
+ 400080,
+ "Transliteration isn't supported for the language or script.",
+ BadRequestException::new,
+ RestRequestHttpResponseCode.BAD_REQUEST),
+ REQUEST_NOT_AUTHORIZED(
+ 401000,
+ "The request isn't authorized because credentials are missing or invalid.",
+ UnauthorizedException::new,
+ RestRequestHttpResponseCode.UNAUTHORIZED),
+ WRONG_CREDENTIALS_PROVIDED(
+ 401015,
+ "The credentials provided are for the Speech API. This request requires credentials for the"
+ + " Text API. Use a subscription to Translator.",
+ UnauthorizedException::new,
+ RestRequestHttpResponseCode.UNAUTHORIZED),
+ OPERATION_NOT_ALLOWED(
+ 403000,
+ "The operation isn't allowed.",
+ ForbiddenException::new,
+ RestRequestHttpResponseCode.FORBIDDEN),
+ FREE_QUOTA_EXCEEDED(
+ 403001,
+ "The operation isn't allowed because the subscription has exceeded its free quota.",
+ ForbiddenException::new,
+ RestRequestHttpResponseCode.FORBIDDEN),
+ REQUEST_METHOD_NOT_SUPPORTED(
+ 405000,
+ "The request method isn't supported for the requested resource.",
+ MethodNotAllowedException::new,
+ RestRequestHttpResponseCode.METHOD_NOT_ALLOWED),
+ TRANSLATION_SYSTEM_BEING_PREPARED(
+ 408001,
+ "The translation system requested is being prepared. Retry in a few minutes.",
+ RequestTimeoutException::new,
+ RestRequestHttpResponseCode.REQUEST_TIMEOUT),
+ REQUEST_TIMED_OUT(
+ 408002,
+ "Request timed out waiting on incoming stream. The client didn't produce a request within the"
+ + " time that the server was prepared to wait. The client may repeat the request without"
+ + " modifications at any later time.",
+ RequestTimeoutException::new,
+ RestRequestHttpResponseCode.REQUEST_TIMEOUT),
+ CONTENT_TYPE_HEADER_INVALID(
+ 415000,
+ "The Content-Type header is missing or invalid.",
+ UnsupportedMediaTypeException::new,
+ RestRequestHttpResponseCode.UNSUPPORTED_MEDIA_TYPE),
+ REQUEST_LIMITS_EXCEEDED(
+ 429000, "The server rejected the request because the client has exceeded request limits."),
+ UNEXPECTED_ERROR_OCCURRED(
+ 500000,
+ "An unexpected error occurred. If the error persists, report it with date/time of error,"
+ + " request identifier from response header X-RequestId, and client identifier from"
+ + " request header X-ClientTraceId.",
+ InternalServerErrorException::new,
+ RestRequestHttpResponseCode.INTERNAL_SERVER_ERROR),
+ SERVICE_TEMPORARILY_UNAVAILABLE(
+ 503000,
+ "Service is temporarily unavailable. Retry. If the error persists, report it with date/time"
+ + " of error, request identifier from response header X-RequestId, and client identifier"
+ + " from request header X-ClientTraceId.",
+ ServiceUnavailableException::new,
+ RestRequestHttpResponseCode.SERVICE_UNAVAILABLE);
+ ;
- TARGET_LANGUAGE_NOT_VALID(400036,
- "The target language is not valid or target language field is missing", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- BODY_REQUEST_NOT_VALID_JSON(400074,
- "The body of the request is not valid JSON.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- REQUEST_INPUT_INVALID(400000, "One of the request inputs isn't valid.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- SCOPE_PARAMETER_INVALID(400001, "The \"scope\" parameter is invalid.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- CATEGORY_PARAMETER_INVALID(400002, "The \"category\" parameter is invalid.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- LANGUAGE_SPECIFIER_INVALID(400003, "A language specifier is missing or invalid.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- TARGET_SCRIPT_SPECIFIER_INVALID(400004, "A target script specifier (\"To script\") is missing or invalid.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- INPUT_TEXT_INVALID(400005, "An input text is missing or invalid.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- LANGUAGE_SCRIPT_COMBINATION_INVALID(400006, "The combination of language and script isn't valid.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- SOURCE_SCRIPT_SPECIFIER_INVALID(400018, "A source script specifier (\"From script\") is missing or invalid.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- SPECIFIED_LANGUAGE_UNSUPPORTED(400019, "One of the specified languages isn't supported.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- INPUT_TEXT_ARRAY_ELEMENT_INVALID(400020, "One of the elements in the array of input text isn't valid.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- API_VERSION_PARAMETER_INVALID(400021, "The API version parameter is missing or invalid.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- SPECIFIED_LANGUAGE_PAIR_INVALID(400023, "One of the specified language pair isn't valid.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- SOURCE_LANGUAGE_INVALID(400035, "The source language (\"From\" field) isn't valid.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- OPTIONS_FIELD_INVALID(400042, "One of the options specified (\"Options\" field) isn't valid.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- CLIENT_TRACE_ID_INVALID(400043, "The client trace ID (ClientTraceId field or X-ClientTranceId header) is missing or invalid.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- INPUT_TEXT_TOO_LONG(400050, "The input text is too long. View request limits.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- TRANSLATION_PARAMETER_INVALID(400064, "The \"translation\" parameter is missing or invalid.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- TARGET_SCRIPTS_NOT_MATCH_TARGET_LANGUAGES(400070, "The number of target scripts (ToScript parameter) doesn't match the number of target languages (To parameter).", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- TEXT_TYPE_INVALID(400071, "The value isn't valid for TextType.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- INPUT_TEXT_ARRAY_TOO_MANY_ELEMENTS(400072, "The array of input text has too many elements.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- SCRIPT_PARAMETER_INVALID(400073, "The script parameter isn't valid.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- LANGUAGE_PAIR_CATEGORY_COMBINATION_INVALID(400075, "The language pair and category combination isn't valid.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- REQUEST_SIZE_EXCEEDED(400077, "The maximum request size has been exceeded. View request limits.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- CUSTOM_SYSTEM_NOT_EXIST(400079, "The custom system requested for translation between from and to language doesn't exist.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- TRANSLITERATION_NOT_SUPPORTED(400080, "Transliteration isn't supported for the language or script.", BadRequestException::new, RestRequestHttpResponseCode.BAD_REQUEST),
- REQUEST_NOT_AUTHORIZED(401000, "The request isn't authorized because credentials are missing or invalid.", UnauthorizedException::new, RestRequestHttpResponseCode.UNAUTHORIZED),
- WRONG_CREDENTIALS_PROVIDED(401015, "The credentials provided are for the Speech API. This request requires credentials for the Text API. Use a subscription to Translator.", UnauthorizedException::new, RestRequestHttpResponseCode.UNAUTHORIZED),
- OPERATION_NOT_ALLOWED(403000, "The operation isn't allowed.", ForbiddenException::new, RestRequestHttpResponseCode.FORBIDDEN),
- FREE_QUOTA_EXCEEDED(403001, "The operation isn't allowed because the subscription has exceeded its free quota.", ForbiddenException::new, RestRequestHttpResponseCode.FORBIDDEN),
- REQUEST_METHOD_NOT_SUPPORTED(405000, "The request method isn't supported for the requested resource.", MethodNotAllowedException::new, RestRequestHttpResponseCode.METHOD_NOT_ALLOWED),
- TRANSLATION_SYSTEM_BEING_PREPARED(408001, "The translation system requested is being prepared. Retry in a few minutes.", RequestTimeoutException::new, RestRequestHttpResponseCode.REQUEST_TIMEOUT),
- REQUEST_TIMED_OUT(408002, "Request timed out waiting on incoming stream. The client didn't produce a request within the time that the server was prepared to wait. The client may repeat the request without modifications at any later time.", RequestTimeoutException::new, RestRequestHttpResponseCode.REQUEST_TIMEOUT),
- CONTENT_TYPE_HEADER_INVALID(415000, "The Content-Type header is missing or invalid.", UnsupportedMediaTypeException::new, RestRequestHttpResponseCode.UNSUPPORTED_MEDIA_TYPE),
- REQUEST_LIMITS_EXCEEDED(429000, "The server rejected the request because the client has exceeded request limits."),
- UNEXPECTED_ERROR_OCCURRED(500000, "An unexpected error occurred. If the error persists, report it with date/time of error, request identifier from response header X-RequestId, and client identifier from request header X-ClientTraceId.", InternalServerErrorException::new, RestRequestHttpResponseCode.INTERNAL_SERVER_ERROR),
- SERVICE_TEMPORARILY_UNAVAILABLE(503000, "Service is temporarily unavailable. Retry. If the error persists, report it with date/time of error, request identifier from response header X-RequestId, and client identifier from request header X-ClientTraceId.", ServiceUnavailableException::new, RestRequestHttpResponseCode.SERVICE_UNAVAILABLE);
- ;
-
- /**
- * A map for retrieving the enum instances by code.
- */
- private static final Map