use serde::Serialize; #[derive(Debug, Clone, Serialize)] pub struct ErrorResponse { pub error: ApiError, } #[derive(Debug, Clone, Serialize)] pub struct ApiError { pub message: String, #[serde(rename = "type")] pub error_type: String, #[serde(skip_serializing_if = "Option::is_none")] pub param: Option, #[serde(skip_serializing_if = "Option::is_none")] pub code: Option, } impl ApiError { pub fn new(message: impl Into, error_type: impl Into) -> Self { Self { message: message.into(), error_type: error_type.into(), param: None, code: None, } } pub fn with_code(mut self, code: impl Into) -> Self { self.code = Some(code.into()); self } pub fn with_param(mut self, param: impl Into) -> Self { self.param = Some(param.into()); self } }