#[request_error_data]Expand description
Extracts request error data into a variable with panic on missing value.
This attribute macro retrieves request error information if an error occurred during handling and makes it available as a variable. If no error data exists, the function will panic with an error message.
§Usage
use hyperlane::*;
use hyperlane_macros::*;
#[route("/request_error_data")]
struct RequestErrorDataTest;
impl ServerHook for RequestErrorDataTest {
async fn new(_ctx: &Context) -> Self {
Self
}
#[response_body(&format!("Request error data: {request_error_data}"))]
#[request_error_data(request_error_data)]
async fn handle(self, ctx: &Context) {}
}
impl RequestErrorDataTest {
#[request_error_data(request_error_data)]
async fn request_error_data_with_ref_self(&self, ctx: &Context) {}
}
#[request_error_data(request_error_data)]
async fn standalone_request_error_data_handler(ctx: &Context) {}The macro accepts a variable name that will contain the request error data.
The variable will be available as a RequestError in the function scope.
§Multi-Parameter Usage
use hyperlane::*;
use hyperlane_macros::*;
#[route("/request_error_data")]
struct MultiRequestErrorData;
impl ServerHook for MultiRequestErrorData {
async fn new(_ctx: &Context) -> Self {
Self
}
#[response_body(&format!("error1: {error1}, error2: {error2}"))]
#[request_error_data(error1, error2)]
async fn handle(self, ctx: &Context) {}
}The macro accepts multiple variable names separated by commas.
§Panics
This macro will panic if no request error data exists in the request context.