use poem::http::StatusCode;
use poem_openapi::{Object, payload::Json};
#[derive(Object, Debug)]
pub struct RespuestaError {
pub codigo: String,
pub mensaje: String,
}
impl RespuestaError {
pub fn from_codigo(code: impl Into<String>) -> Self {
let code = code.into();
Self {
mensaje: code.clone(),
codigo: code,
}
}
}
pub trait IntoRespuestaError {
fn into_respuesta_error(self) -> (StatusCode, Json<RespuestaError>);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn should_carry_the_code_in_name_and_message_when_built_from_a_code() {
let body = RespuestaError::from_codigo("product.not_found");
assert_eq!(body.codigo, "product.not_found");
assert_eq!(body.mensaje, "product.not_found");
}
}