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 AnkaSecureSdkException
Translates an exception into anAnkaSecureSdkException
with a human-readable message.static AnkaSecureSdkException
Translates an exception into anAnkaSecureSdkException
using a localized message.
-
Method Details
-
translateI18n
public static AnkaSecureSdkException translateI18n(String key, Exception cause, Map<String, String> ctx, Object... args) Translates an exception into anAnkaSecureSdkException
using a localized message.The message is obtained by looking up
key
in the resource bundle and formatting it withMessageFormat
using 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
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 anAnkaSecureSdkException
with a human-readable message.If the
cause
is anApiException
, its HTTP status code and response body will be extracted and included. Thectx
map is copied to prevent external mutation. The resulting exception’serror code
is 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
AnkaSecureSdkException
with provided message, cause, HTTP info, and classified error code - Throws:
NullPointerException
- ifhumanMessage
orcause
isnull
- Since:
- 1.0.0
-