mirror of
https://git.proxmox.com/git/proxmox
synced 2025-05-29 00:56:52 +00:00
37 lines
773 B
Rust
37 lines
773 B
Rust
use std::fmt;
|
|
|
|
use failure::Fail;
|
|
|
|
#[doc(hidden)]
|
|
pub use hyper::StatusCode;
|
|
|
|
/// HTTP error including `StatusCode` and message.
|
|
#[derive(Debug, Fail)]
|
|
pub struct HttpError {
|
|
pub code: StatusCode,
|
|
pub message: String,
|
|
}
|
|
|
|
impl HttpError {
|
|
pub fn new(code: StatusCode, message: String) -> Self {
|
|
HttpError { code, message }
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for HttpError {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
write!(f, "{}", self.message)
|
|
}
|
|
}
|
|
|
|
/// Macro to create a HttpError inside a failure::Error
|
|
#[macro_export]
|
|
macro_rules! http_err {
|
|
($status:ident, $msg:expr) => {{
|
|
::failure::Error::from($crate::error::HttpError::new(
|
|
$crate::error::StatusCode::$status,
|
|
$msg,
|
|
))
|
|
}};
|
|
}
|