Class AwsErrors

java.lang.Object
codes.grow.packages.awssecretsmanager.AwsErrors

public final class AwsErrors extends Object
Maps AWS SDK errors to the SPEC section 2.1 error classes by AWS error code (AWS JSON services answer HTTP 400 for throttling and access denied, so status mapping alone is wrong; see API.md section 1.1). The HTTP status is only the fallback.
  • Field Details

    • CODES

      public static final Map<String,ErrorCode> CODES
      AWS error code to canonical code.
  • Method Details

    • codeFor

      public static Optional<ErrorCode> codeFor(String awsCode)
      Returns the canonical code of an AWS error code.
      Parameters:
      awsCode - AWS error code such as ResourceNotFoundException, may be null
      Returns:
      the code, or empty when unknown
    • awsErrorCode

      public static Optional<String> awsErrorCode(Throwable error)
      Returns the AWS error code behind an error (the error itself or one of its causes).
      Parameters:
      error - any throwable, may be null
      Returns:
      the AWS error code, or empty when the error did not come from an AWS error response
    • codeFromBody

      public static Optional<String> codeFromBody(String text)
      Extracts an error code from an XML (<Code>) or JSON (__type) error body.
      Parameters:
      text - body text, may be null
      Returns:
      the code, or empty
    • map

      public static AwsSecretsManagerException map(Throwable error, String operation, Collection<String> knownSecrets, Duration totalTimeout)
      Converts anything the AWS SDK throws into an SDK exception with the message "<operation>: <AwsCode>: <redacted vendor text> (HTTP <status>)". Known secret values are redacted; request bodies never appear.
      Parameters:
      error - the error
      operation - Grow operation, e.g. "getSecretValue app/db"
      knownSecrets - values to redact
      totalTimeout - the configured total timeout (for the message), may be null
      Returns:
      the mapped exception (an SDK exception is returned unchanged)