mini-serve 0.13.12

An HTTP server: trie router, middleware, CORS, optional TLS. Built on hyper + tokio.
Documentation
use std::fmt;

/// An HTTP error returned by a handler.
///
/// Contains an HTTP status code and a message. The message is sanitized
/// before being sent to clients for 5xx errors (only generic "internal server error"
/// is shown), but passed through for 4xx errors.
#[derive(Debug)]
pub struct ServeError {
	/// HTTP status code (e.g., 400, 500).
	pub code:    u16,
	/// Error message (shown to client for 4xx, sanitized for 5xx).
	pub message: String,
}

impl ServeError {
	/// Create a new error with a status code and message.
	pub fn new(code: u16, message: impl Into<String>) -> Self {
		ServeError { code, message: message.into() }
	}
}

impl fmt::Display for ServeError {
	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
		write!(f, "{}: {}", self.code, self.message)
	}
}

impl std::error::Error for ServeError {}