Sep31UnauthorizedException

class Sep31UnauthorizedException(message: String, val statusCode: Int = 401, val rawResponseBody: String? = null) : Sep31Exception

Exception thrown when the Receiving Anchor returns HTTP 401 Unauthorized.

Indicates that the SEP-10 JWT used to authenticate the request was missing, malformed, or expired. The SEP-31 specification mandates HTTP 403 for authentication failures (see spec "Authentication" section), but real-world anchors also emit HTTP 401; the SDK handles both. Catch Sep31UnauthorizedException for the 401 path and Sep31ForbiddenException for the 403 path.

Common causes:

  • The SEP-10 JWT has expired

  • The Authorization: Bearer <jwt> header is missing entirely

  • The JWT signature did not validate against the anchor's signing key

Recovery actions:

  • Obtain a fresh SEP-10 JWT and retry the request

  • Verify the JWT issuer matches the anchor's expected issuer

Example - Handle unauthorized:

try {
val transaction = sep31Service.getTransaction(id = "11111111-1111-1111-1111-111111111111", jwt = jwt)
} catch (e: Sep31UnauthorizedException) {
println("Authentication required (HTTP ${e.statusCode}): ${e.message}")
// Re-authenticate via SEP-10 and retry
}

See also:

Parameters

message

Sanitized error message extracted from the anchor response.

Constructors

Link copied to clipboard
constructor(message: String, statusCode: Int = 401, rawResponseBody: String? = null)

Properties

Link copied to clipboard
expect open val cause: Throwable?
Link copied to clipboard
expect open val message: String?
Link copied to clipboard

Anchor response body for local debugging — see the rawResponseBody convention on Sep31Exception. null when no body was captured.

Link copied to clipboard

The HTTP status code returned by the Receiving Anchor (always 401 for this exception).

Functions

Link copied to clipboard
open override fun toString(): String