pub enum AppMessage {
Success(String),
Redirect(String),
Invalid(String),
Unauthorized(String),
Forbidden(String),
NotFound(String),
Conflict(String),
UnprocessableEntity(String),
ValidationError(String, ValidationErrors),
InternalServerError(String),
ErrorMessage(String, StatusCode),
MissingEnvironmentVariable(String, VarError),
}Variants§
Success(String)
Redirect(String)
Invalid(String)
Forbidden(String)
NotFound(String)
Conflict(String)
UnprocessableEntity(String)
ValidationError(String, ValidationErrors)
InternalServerError(String)
ErrorMessage(String, StatusCode)
MissingEnvironmentVariable(String, VarError)
Implementations§
Source§impl AppMessage
impl AppMessage
Sourcepub fn invalid(msg: impl Into<String>) -> Self
pub fn invalid(msg: impl Into<String>) -> Self
Creates a new invalid request message (400 Bad Request).
Creates a new unauthorized message (401).
Sourcepub fn unprocessable_entity(msg: impl Into<String>) -> Self
pub fn unprocessable_entity(msg: impl Into<String>) -> Self
Creates a new unprocessable entity message (422).
Sourcepub fn validation_error(
msg: impl Into<String>,
errors: impl Into<ValidationErrors>,
) -> Self
pub fn validation_error( msg: impl Into<String>, errors: impl Into<ValidationErrors>, ) -> Self
Creates a validation error (422) with per-field error details.
§Example
use foxtive::enums::AppMessage;
use foxtive::ValidationErrors;
let mut errors = ValidationErrors::new();
errors.insert("email".into(), vec!["is required".into()]);
let msg = AppMessage::validation_error("Validation failed", errors);Sourcepub fn internal_server_error(msg: impl Into<String>) -> Self
pub fn internal_server_error(msg: impl Into<String>) -> Self
Creates a new internal server error message (500).
Sourcepub fn error_message(msg: impl Into<String>, status: StatusCode) -> Self
pub fn error_message(msg: impl Into<String>, status: StatusCode) -> Self
Creates an error message with an explicit status code.
Sourcepub fn missing_environment_variable(
name: impl Into<String>,
error: VarError,
) -> Self
pub fn missing_environment_variable( name: impl Into<String>, error: VarError, ) -> Self
Creates a missing environment variable error (500).
Sourcepub fn status_code(&self) -> StatusCode
pub fn status_code(&self) -> StatusCode
Returns the HTTP status code associated with this message.
Sourcepub fn validation_errors(&self) -> Option<&ValidationErrors>
pub fn validation_errors(&self) -> Option<&ValidationErrors>
Returns field-level validation errors, if this is a ValidationError.
Sourcepub fn kind_name(&self) -> &'static str
pub fn kind_name(&self) -> &'static str
Returns a stable string identifier for the variant (useful for logging/tracing).
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Returns true if the status code is 2xx.
Sourcepub fn is_redirect(&self) -> bool
pub fn is_redirect(&self) -> bool
Returns true if the status code is 3xx.
Sourcepub fn is_client_error(&self) -> bool
pub fn is_client_error(&self) -> bool
Returns true if the status code is 4xx.
Sourcepub fn is_server_error(&self) -> bool
pub fn is_server_error(&self) -> bool
Returns true if the status code is 5xx.
Sourcepub fn log(&self)
pub fn log(&self)
Logs the message at the appropriate tracing level, including kind and status.
Sourcepub fn into_anyhow(self) -> Error
pub fn into_anyhow(self) -> Error
Converts into an anyhow::Error.
Sourcepub fn into_result<T>(self) -> AppResult<T>
pub fn into_result<T>(self) -> AppResult<T>
Converts into an AppResult<T> (always Err).
Trait Implementations§
Source§impl Clone for AppMessage
impl Clone for AppMessage
Source§fn clone(&self) -> AppMessage
fn clone(&self) -> AppMessage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AppMessage
impl Debug for AppMessage
Source§impl Display for AppMessage
impl Display for AppMessage
Source§impl Error for AppMessage
impl Error for AppMessage
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()