#[request_error_data_option]Expand description
Extracts request error data into a variable wrapped in Option type.
This attribute macro retrieves request error information if an error occurred during handling and makes it available as an Option variable. The extracted value is wrapped in an Option type to safely handle cases where no error occurred.
§Usage
use hyperlane::*;
use hyperlane_macros::*;
#[route("/request_error_data_option")]
struct RequestErrorDataOptionTest;
impl ServerHook for RequestErrorDataOptionTest {
async fn new(_ctx: &Context) -> Self {
Self
}
#[response_body(&format!("Request error data: {request_error_data_option:?}"))]
#[request_error_data_option(request_error_data_option)]
async fn handle(self, ctx: &Context) {}
}
impl RequestErrorDataOptionTest {
#[request_error_data_option(request_error_data_option)]
async fn request_error_data_option_with_ref_self(&self, ctx: &Context) {}
}
#[request_error_data_option(request_error_data_option)]
async fn standalone_request_error_data_option_handler(ctx: &Context) {}The macro accepts a variable name that will contain the request error data.
The variable will be available as an Option<RequestError> in the function scope.
§Multi-Parameter Usage
use hyperlane::*;
use hyperlane_macros::*;
#[route("/request_error_data_option")]
struct MultiRequestErrorDataOption;
impl ServerHook for MultiRequestErrorDataOption {
async fn new(_ctx: &Context) -> Self {
Self
}
#[response_body(&format!("error1: {error1:?}, error2: {error2:?}"))]
#[request_error_data_option(error1, error2)]
async fn handle(self, ctx: &Context) {}
}The macro accepts multiple variable names separated by commas.