Class ExceptionTranslator

java.lang.Object
co.ankatech.ankasecure.sdk.internal.util.ExceptionTranslator

public final class ExceptionTranslator extends Object
Utility class for translating any checked or runtime exception (including OpenAPI ApiException) into a uniform AnkaSecureSdkException, enriched with:
  • HTTP status code (if available)
  • Raw response body (if available)
  • Human-readable message, optionally localized
  • SDK-specific error code classification
  • Arbitrary context data for diagnostics

Use translateI18n(String, Exception, Map, Object...) for localization-ready messages from a resource bundle, or translate(String, Exception, Map) for plain messages.

Since:
1.0.0
  • Method Details

    • translateI18n

      public static AnkaSecureSdkException translateI18n(String key, Exception cause, Map<String,String> ctx, Object... args)
      Translates an exception into an AnkaSecureSdkException using a localized message.

      The message is obtained by looking up key in the resource bundle and formatting it with MessageFormat using the supplied args.

      Parameters:
      key - the message key in the resource bundle
      cause - the original exception to translate (must not be null)
      ctx - additional context key-value pairs (may be null)
      args - arguments to format into the localized message
      Returns:
      a new AnkaSecureSdkException with localized message, cause, HTTP info, and classified error code
      Throws:
      MissingResourceException - if the key is not found in the bundle
      Since:
      1.0.0
    • translate

      public static AnkaSecureSdkException translate(String humanMessage, Exception cause, Map<String,String> ctx)
      Translates an exception into an AnkaSecureSdkException with a human-readable message.

      If the cause is an ApiException, its HTTP status code and response body will be extracted and included. The ctx map is copied to prevent external mutation. The resulting exception’s error code is determined by classify(Exception).

      Parameters:
      humanMessage - the detail message for the translated exception (must not be null)
      cause - the original exception to translate (must not be null)
      ctx - additional context key-value pairs (may be null)
      Returns:
      a new AnkaSecureSdkException with provided message, cause, HTTP info, and classified error code
      Throws:
      NullPointerException - if humanMessage or cause is null
      Since:
      1.0.0