Files
ForgeLM/crates/api-contracts/src/error.rs
T

39 lines
941 B
Rust

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<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub code: Option<String>,
}
impl ApiError {
pub fn new(message: impl Into<String>, error_type: impl Into<String>) -> Self {
Self {
message: message.into(),
error_type: error_type.into(),
param: None,
code: None,
}
}
pub fn with_code(mut self, code: impl Into<String>) -> Self {
self.code = Some(code.into());
self
}
pub fn with_param(mut self, param: impl Into<String>) -> Self {
self.param = Some(param.into());
self
}
}