use crate::{
error::{BoxError, ServerError},
web::IntoResponse,
};
use http::StatusCode;
use std::fmt::Display;
pub fn bad_request(msg: impl Display) -> BoxError {
ServerError::new(StatusCode::BAD_REQUEST, msg).into()
}
pub fn bad_request_with<T>(error: T) -> BoxError
where
T: IntoResponse + Send + Sync + Clone + 'static,
{
ServerError::from_response_and_status(StatusCode::BAD_REQUEST, error).into()
}
pub fn unauthorized(msg: impl Display) -> BoxError {
ServerError::new(StatusCode::UNAUTHORIZED, msg).into()
}
pub fn unauthorized_with<T>(error: T) -> BoxError
where
T: IntoResponse + Send + Sync + Clone + 'static,
{
ServerError::from_response_and_status(StatusCode::UNAUTHORIZED, error).into()
}
pub fn forbidden(msg: impl Display) -> BoxError {
ServerError::new(StatusCode::FORBIDDEN, msg).into()
}
pub fn forbidden_with<T>(error: T) -> BoxError
where
T: IntoResponse + Send + Sync + Clone + 'static,
{
ServerError::from_response_and_status(StatusCode::FORBIDDEN, error).into()
}
pub fn not_found(msg: impl Display) -> BoxError {
ServerError::new(StatusCode::NOT_FOUND, msg).into()
}
pub fn not_found_with<T>(error: T) -> BoxError
where
T: IntoResponse + Send + Sync + Clone + 'static,
{
ServerError::from_response_and_status(StatusCode::NOT_FOUND, error).into()
}
pub fn method_not_allowed(msg: impl Display) -> BoxError {
ServerError::new(StatusCode::METHOD_NOT_ALLOWED, msg).into()
}
pub fn method_not_allowed_with<T>(error: T) -> BoxError
where
T: IntoResponse + Send + Sync + Clone + 'static,
{
ServerError::from_response_and_status(StatusCode::METHOD_NOT_ALLOWED, error).into()
}
pub fn conflict(msg: impl Display) -> BoxError {
ServerError::new(StatusCode::CONFLICT, msg).into()
}
pub fn conflict_with<T>(error: T) -> BoxError
where
T: IntoResponse + Send + Sync + Clone + 'static,
{
ServerError::from_response_and_status(StatusCode::CONFLICT, error).into()
}
pub fn unprocessable_entity(msg: impl Display) -> BoxError {
ServerError::new(StatusCode::UNPROCESSABLE_ENTITY, msg).into()
}
pub fn unprocessable_entity_with<T>(error: T) -> BoxError
where
T: IntoResponse + Send + Sync + Clone + 'static,
{
ServerError::from_response_and_status(StatusCode::UNPROCESSABLE_ENTITY, error).into()
}
pub fn internal_server_error(msg: impl Display) -> BoxError {
ServerError::new(StatusCode::INTERNAL_SERVER_ERROR, msg).into()
}
pub fn internal_server_error_with<T>(error: T) -> BoxError
where
T: IntoResponse + Send + Sync + Clone + 'static,
{
ServerError::from_response_and_status(StatusCode::INTERNAL_SERVER_ERROR, error).into()
}