use sputnik::hyper_body::FormError; use sputnik::request::QueryError; use std::str::Utf8Error; /// For convenience this enum also contains nonerroneous variants. pub enum Error { /// A 400 bad request error. BadRequest(String), /// A 401 unauthorized error. Unauthorized(String), /// A 403 forbidden error. Forbidden(String), /// A 404 not found error. NotFound(String), /// A 500 internal server error. Internal(String), /// A 304 response. NotModified, /// A 302 redirect to the given path. Redirect(String), // TODO: use Redirect instead /// Missing trailing slash. MissingTrailingSlash(String), } impl From for Error { fn from(_: Utf8Error) -> Self { Self::BadRequest("invalid UTF-8".into()) } } impl From for Error { fn from(e: git2::Error) -> Self { eprintln!("git error: {}", e); Self::Internal("something went wrong with git".into()) } } impl From for Error { fn from(e: FormError) -> Self { Self::BadRequest(e.to_string()) } } impl From for Error { fn from(e: QueryError) -> Self { Self::BadRequest(e.to_string()) } }