pub struct ApiError {
pub code: String,
pub category: ErrorCategory,
pub message: String,
pub details: Option<String>,
pub remediation: Vec<String>,
pub context: ErrorContext,
pub retry_after_secs: Option<u64>,
}Expand description
Unified API error structure.
This type is used for all error responses in both CLI and daemon APIs.
It uses the ErrorCode enum for consistent error identification.
§Example
use rch_common::api::ApiError;
use rch_common::ErrorCode;
let error = ApiError::from_code(ErrorCode::SshConnectionFailed)
.with_message("Connection refused")
.with_context("worker_id", "worker-1")
.with_context("host", "192.168.1.100");
assert_eq!(error.code, "RCH-E100");Fields§
§code: StringError code in RCH-Exxx format (e.g., “RCH-E100”).
category: ErrorCategoryError category for quick classification.
message: StringHuman-readable error message.
details: Option<String>Detailed description of what went wrong.
remediation: Vec<String>Suggested remediation steps.
context: ErrorContextAdditional context information.
retry_after_secs: Option<u64>Optional retry-after hint in seconds (for rate limiting).
Implementations§
Source§impl ApiError
impl ApiError
Sourcepub fn from_code(code: ErrorCode) -> Self
pub fn from_code(code: ErrorCode) -> Self
Create an ApiError from an ErrorCode.
Automatically populates the code string, category, message, and remediation from the error catalog.
Sourcepub fn new(code: ErrorCode, message: impl Into<String>) -> Self
pub fn new(code: ErrorCode, message: impl Into<String>) -> Self
Create an ApiError with a custom message.
Sourcepub fn with_message(self, message: impl Into<String>) -> Self
pub fn with_message(self, message: impl Into<String>) -> Self
Add or replace the detailed message.
Sourcepub fn with_details(self, details: impl Into<String>) -> Self
pub fn with_details(self, details: impl Into<String>) -> Self
Alias for with_message for clarity.
Sourcepub fn with_context(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_context( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Add a context field.
Sourcepub fn with_context_map(self, map: HashMap<String, String>) -> Self
pub fn with_context_map(self, map: HashMap<String, String>) -> Self
Add multiple context fields.
Sourcepub fn with_retry_after(self, seconds: u64) -> Self
pub fn with_retry_after(self, seconds: u64) -> Self
Set retry-after hint for rate limiting errors.
Sourcepub fn with_remediation(
self,
steps: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn with_remediation( self, steps: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Add additional remediation steps.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ApiError
impl<'de> Deserialize<'de> for ApiError
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Error for ApiError
impl Error for ApiError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl JsonSchema for ApiError
impl JsonSchema for ApiError
Source§fn schema_name() -> String
fn schema_name() -> String
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref keyword. Read more