Skip to main content

as_chatbot_error

Function as_chatbot_error 

Source
pub fn as_chatbot_error<E>(
    error_type: ChatbotErrorType,
    message: impl Into<String>,
) -> impl FnOnce(E) -> ChatbotError
where E: Into<Error>,
Expand description

Helper function for .map_err() chains to wrap any error as ChatbotError.

This function creates a closure that converts any error into a ChatbotError with the specified error type and message, including the original error as the source.

§Examples

// Instead of:
.map_err(|e| ChatbotError::new(ChatbotErrorType::Other, e.to_string(), Some(e.into())))?

// You can write:
.map_err(as_chatbot_error(ChatbotErrorType::Other, "Failed to process".to_string()))?