proxmox/proxmox-api/src/error.rs
Wolfgang Bumiller 2d12f81235 api: use http::{Parts,Response,Method}
hyper just reexports them

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-05 13:18:21 +01:00

37 lines
772 B
Rust

use std::fmt;
use failure::Fail;
#[doc(hidden)]
pub use http::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,
))
}};
}