Struct coap_message_utils::Error
source · pub struct Error { /* private fields */ }Expand description
A build-time-flexible renderable error type
This is used wherever this crate produces errors, and also recommended for outside handlers – the idea being that the more code parts share a type, the more compact code can be emitted.
Depending on what gets configured, it may just be a single u8 error code, or it may contain more details such as the number of the option that could not be processed, or any other Standard Problem Details (RFC9290).
Implementations§
source§impl Error
impl Error
sourcepub fn bad_option(unprocessed_option: u16) -> Self
pub fn bad_option(unprocessed_option: u16) -> Self
Create an error response for an unprocessed option
The response is rendered with a single unprocessed-coap-option problem detail if that feature is enabled.
If the unprocessed option has a special error code (e.g. Accept => 4.06 Not Acceptable or Content Format => 4.15 Unsupported Content-Format), that code is emitted instead of the default 4.02 Bad Option, and the unprocessed-coap-option problem details is not emitted.
Note that the CoAP option number is given as a u16, as is common around the CoAP crates (even though 0 is a reseved value). It is an error to pass in the value 0; the implementation may treat this as a reason for a panic, or silently ignore the error and not render the problem detail.
sourcepub fn bad_request_with_rbep(byte: usize) -> Self
pub fn bad_request_with_rbep(byte: usize) -> Self
Create a 4.00 Bad Request error with a Request Body Error Position indicating at which position in the request’s body the error occurred
If the crate is compiled without the error_request_body_error_position feature, the
position information will be ignored. The value may also be ignored if it exceeds an
internal limit of how large values can be expressed.
sourcepub fn bad_request() -> Self
pub fn bad_request() -> Self
Create an otherwise empty 4.00 Bad Request error
sourcepub fn method_not_allowed() -> Self
pub fn method_not_allowed() -> Self
Create an otherwise empty 4.05 Method Not Allowed error
sourcepub fn internal_server_error() -> Self
pub fn internal_server_error() -> Self
Create an otherwise empty 5.00 Internal Server Error error
Create an otherwise empty 5.03 Service Unavailable error
sourcepub fn with_max_age(self, max_age: u32) -> Self
Available on crate feature error_max_age only.
pub fn with_max_age(self, max_age: u32) -> Self
error_max_age only.Set a Max-Age
Unlike the constructors that set error details, this modifier is only available when the data is actually stored, because not emitting it is not just elision of possibly helful details, but may change the networks’ behavior (for example, because a long Max-Age is not sent and the client keeps retrying every minute).