Class ExceptionTranslator
java.lang.Object
co.ankatech.ankasecure.sdk.internal.util.ExceptionTranslator
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 Summary
Modifier and TypeMethodDescriptionstatic AnkaSecureSdkExceptionTranslates an exception into anAnkaSecureSdkExceptionwith a human-readable message.static AnkaSecureSdkExceptionTranslates an exception into anAnkaSecureSdkExceptionusing a localized message.
-
Method Details
-
translateI18n
public static AnkaSecureSdkException translateI18n(String key, Exception cause, Map<String, String> ctx, Object... args) Translates an exception into anAnkaSecureSdkExceptionusing a localized message.The message is obtained by looking up
keyin the resource bundle and formatting it withMessageFormatusing the suppliedargs.- Parameters:
key- the message key in the resource bundlecause- the original exception to translate (must not benull)ctx- additional context key-value pairs (may benull)args- arguments to format into the localized message- Returns:
- a new
AnkaSecureSdkExceptionwith 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 anAnkaSecureSdkExceptionwith a human-readable message.If the
causeis anApiException, its HTTP status code and response body will be extracted and included. Thectxmap is copied to prevent external mutation. The resulting exception’serror codeis determined byclassify(Exception).- Parameters:
humanMessage- the detail message for the translated exception (must not benull)cause- the original exception to translate (must not benull)ctx- additional context key-value pairs (may benull)- Returns:
- a new
AnkaSecureSdkExceptionwith provided message, cause, HTTP info, and classified error code - Throws:
NullPointerException- ifhumanMessageorcauseisnull- Since:
- 1.0.0
-