CoapException

class CoapException(message: String, val reason: CoapException.Reason, cause: Throwable? = null, val response: CoapResponse? = null) : KcoapException(source)

A CoAP exchange that could not complete because of the peer, the network, message security or the endpoint itself: no acknowledgement or a Reset over datagrams, a secure session or connection that ended, a response that violates the protocol or could not be verified, a request that message security could not protect, a host that could not be resolved, or an endpoint that is closed, has no transport for the peer, or whose transport failed. reason says which; the reasons of one transport shape say so. This is the one exception type that CoapClient, CoapEndpoint and CoapServer calls fail with at runtime, a KcoapException like the exceptions of kcoap's other protocols; IllegalArgumentException and IllegalStateException are kept for mistakes of the caller, such as a malformed URI string.

On the client side, responses with error codes (4.xx, 5.xx) are not exceptions: a request returns them as responses. The exception is a protected request answered only by an error that message security could not verify, which ends with Reason.UNVERIFIED_RESPONSE and carries that error as response. On the server side the reverse holds for a handler, which may answer with an error by throwing CoapResponseException.

Reason may gain constants in any minor release, so a when over reason keeps an else branch.

Constructors

Link copied to clipboard
constructor(message: String, reason: CoapException.Reason, cause: Throwable? = null, response: CoapResponse? = null)

Types

Link copied to clipboard

Why the exchange failed.

Properties

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

the response the exchange ended with without acting on it: for Reason.UNVERIFIED_RESPONSE, the unverified response as it came; null for every other reason.