Class ServerException
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
AlreadyExistsException,ConfigurationException,InternalException,NotAllowedException,NotFoundException,QueryException,SerializationException,ThrownException,ValidationException
Carries structured error information: a machine-readable kind,
optional details using the {kind, details?} wire format,
and an optional typed cause chain.
Details follow the internally-tagged format where each detail object has a
"kind" field and an optional "details" field:
- Unit variant:
{"kind": "Parse"} - Newtype variant:
{"kind": "Auth", "details": {"kind": "TokenExpired"}} - Struct variant:
{"kind": "Table", "details": {"name": "users"}}
For backward compatibility with older servers, the legacy externally-tagged
format ("Parse", {"Auth": "TokenExpired"},
{"Table": {"name": "users"}}) is also supported by all detail helpers.
Specific error kinds are represented by subclasses (e.g. NotAllowedException,
NotFoundException). When the server returns an unknown kind, a plain
ServerException is used (not InternalException) to preserve forward
compatibility.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionFinds the first error in the cause chain (including this error) that has the givenErrorKind.Finds the first error in the cause chain (including this error) that has the givenkind.Returns the optional structured details for this error.getKind()Returns the machine-readable error kind string (e.g.Returns the error kind as an enum for type-safe matching.Returns the typed server-side cause of this error, if any.booleanChecks whether this error or any error in its cause chain has the givenErrorKind.booleanChecks whether this error or any error in its cause chain has the givenkind.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Method Details
-
getKind
Returns the machine-readable error kind string (e.g."NotAllowed"). For unknown kinds this is the wire string; otherwise it matchesgetKindEnum().getRaw().- Returns:
- the error kind string, never
null
-
getKindEnum
Returns the error kind as an enum for type-safe matching. Unknown kinds from newer servers map toErrorKind.UNKNOWN; the raw string is ingetKind().- Returns:
- the error kind enum, never
null
-
getDetails
Returns the optional structured details for this error.Details use the
{kind, details?}wire format. The value is either:null-- no details- a
Map<String, Object>with a"kind"key and optional"details"key (new internally-tagged format) - a
String-- a unit variant in the legacy format (e.g."Parse") - a
Map<String, Object>without"kind"-- legacy externally-tagged format
Prefer the typed convenience getters on subclasses (e.g.
NotFoundException.getTableName()) over inspecting details directly.- Returns:
- the details object, or
null
-
getServerCause
Returns the typed server-side cause of this error, if any.This is equivalent to calling
Throwable.getCause()and casting toServerException, but avoids the cast.- Returns:
- the server cause, or
null
-
hasKind
-
hasKind
-
findCause
Finds the first error in the cause chain (including this error) that has the givenkind.- Parameters:
kind- the kind to look for- Returns:
- the matching
ServerException, ornull
-
findCause
Finds the first error in the cause chain (including this error) that has the givenErrorKind.
-