#[derive(Debug, Serialize, Deserialize)]
pub struct ErrorResponse {
code: String,
message: String,
}
impl ErrorResponse {
pub fn internal_error() -> ErrorResponse {
ErrorResponse {
code: "500".to_string(),
message: "The server encountered an error".to_string(),
}
}
pub fn bad_request(message: &str) -> ErrorResponse {
ErrorResponse {
code: "400".to_string(),
message: message.to_string(),
}
}
pub fn not_found(message: &str) -> ErrorResponse {
ErrorResponse {
code: "404".to_string(),
message: message.to_string(),
}
}
pub fn unauthorized() -> ErrorResponse {
ErrorResponse {
code: "401".to_string(),
message: "Client is not authorized".to_string(),
}
}
pub fn forbidden(message: &str) -> ErrorResponse {
ErrorResponse {
code: "403".to_string(),
message: message.to_string(),
}
}
pub fn request_timeout(message: &str) -> ErrorResponse {
ErrorResponse {
code: "408".to_string(),
message: message.to_string(),
}
}
pub fn conflict(message: &str) -> ErrorResponse {
ErrorResponse {
code: "409".to_string(),
message: message.to_string(),
}
}
}