pub trait ExtensionError:
Error
+ Send
+ Sync
+ 'static {
// Required method
fn code(&self) -> &'static str;
// Provided methods
fn status(&self) -> StatusCode { ... }
fn is_retryable(&self) -> bool { ... }
fn user_message(&self) -> String { ... }
fn to_mcp_error(&self) -> McpErrorData { ... }
fn to_api_error(&self) -> ApiError { ... }
}Available on crate feature
core only.Expand description
Trait for extension error types to enable consistent error handling.
This trait provides a unified interface for extension errors that can be converted to both HTTP API responses and MCP protocol errors.
§Example
ⓘ
use systemprompt_traits::{ExtensionError, ApiError, McpErrorData};
use http::StatusCode;
#[derive(Debug, thiserror::Error)]
pub enum MyError {
#[error("Resource not found: {0}")]
NotFound(String),
#[error("Invalid input: {0}")]
InvalidInput(String),
}
impl ExtensionError for MyError {
fn code(&self) -> &'static str {
match self {
Self::NotFound(_) => "NOT_FOUND",
Self::InvalidInput(_) => "INVALID_INPUT",
}
}
fn status(&self) -> StatusCode {
match self {
Self::NotFound(_) => StatusCode::NOT_FOUND,
Self::InvalidInput(_) => StatusCode::BAD_REQUEST,
}
}
}Required Methods§
Provided Methods§
Sourcefn status(&self) -> StatusCode
fn status(&self) -> StatusCode
HTTP status code for API responses.
Sourcefn is_retryable(&self) -> bool
fn is_retryable(&self) -> bool
Whether this error is transient and operation should be retried.
Sourcefn user_message(&self) -> String
fn user_message(&self) -> String
User-facing message (defaults to Display impl).
Sourcefn to_mcp_error(&self) -> McpErrorData
fn to_mcp_error(&self) -> McpErrorData
Convert to MCP protocol error format.
Sourcefn to_api_error(&self) -> ApiError
fn to_api_error(&self) -> ApiError
Convert to API response error.