public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Lukas Wagner <l.wagner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v2 proxmox 2/4] router: re-export `HttpError` from `proxmox-http-error`
Date: Wed, 26 Jul 2023 16:18:22 +0200	[thread overview]
Message-ID: <20230726141824.813621-3-l.wagner@proxmox.com> (raw)
In-Reply-To: <20230726141824.813621-1-l.wagner@proxmox.com>

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-router/Cargo.toml   |  1 +
 proxmox-router/src/error.rs | 42 +------------------------------------
 proxmox-router/src/lib.rs   |  2 +-
 3 files changed, 3 insertions(+), 42 deletions(-)

diff --git a/proxmox-router/Cargo.toml b/proxmox-router/Cargo.toml
index 34a1985..7d4d32f 100644
--- a/proxmox-router/Cargo.toml
+++ b/proxmox-router/Cargo.toml
@@ -26,6 +26,7 @@ rustyline = { version = "9", optional = true }
 libc = { workspace = true, optional = true }
 
 proxmox-lang.workspace = true
+proxmox-http-error.workspace = true
 proxmox-schema.workspace = true
 proxmox-async.workspace = true
 
diff --git a/proxmox-router/src/error.rs b/proxmox-router/src/error.rs
index e285cf7..15c5417 100644
--- a/proxmox-router/src/error.rs
+++ b/proxmox-router/src/error.rs
@@ -1,44 +1,4 @@
-use std::fmt;
+pub use proxmox_http_error::{http_bail, http_err, HttpError};
 
 #[doc(hidden)]
 pub use http::StatusCode;
-
-/// HTTP error including `StatusCode` and message.
-#[derive(Debug)]
-pub struct HttpError {
-    pub code: StatusCode,
-    pub message: String,
-}
-
-impl std::error::Error for HttpError {}
-
-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 anyhow::Error
-#[macro_export]
-macro_rules! http_err {
-    ($status:ident, $($fmt:tt)+) => {{
-        ::anyhow::Error::from($crate::HttpError::new(
-            $crate::error::StatusCode::$status,
-            format!($($fmt)+)
-        ))
-    }};
-}
-
-/// Bail with an error generated with the `http_err!` macro.
-#[macro_export]
-macro_rules! http_bail {
-    ($status:ident, $($fmt:tt)+) => {{
-        return Err($crate::http_err!($status, $($fmt)+));
-    }};
-}
diff --git a/proxmox-router/src/lib.rs b/proxmox-router/src/lib.rs
index 7f4f2d9..808836a 100644
--- a/proxmox-router/src/lib.rs
+++ b/proxmox-router/src/lib.rs
@@ -17,7 +17,7 @@ mod serializable_return;
 
 #[doc(inline)]
 #[cfg(feature = "server")]
-pub use error::HttpError;
+pub use error::*;
 
 pub use permission::*;
 pub use router::*;
-- 
2.39.2





  parent reply	other threads:[~2023-07-26 14:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-26 14:18 [pve-devel] [PATCH v2 proxmox{, -perl-rs} 0/4] move `HttpError` from `proxmox-router` into its own crate Lukas Wagner
2023-07-26 14:18 ` [pve-devel] [PATCH v2 proxmox 1/4] http-error: add new http-error crate Lukas Wagner
2023-07-26 14:18 ` Lukas Wagner [this message]
2023-07-26 14:18 ` [pve-devel] [PATCH v2 proxmox 3/4] notify: use HttpError from proxmox-http-error Lukas Wagner
2023-07-26 14:18 ` [pve-devel] [PATCH v2 proxmox-perl-rs 4/4] notify: use new HttpError type Lukas Wagner
2023-07-28  9:58 ` [pve-devel] applied-series: [PATCH v2 proxmox{, -perl-rs} 0/4] move `HttpError` from `proxmox-router` into its own crate Wolfgang Bumiller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230726141824.813621-3-l.wagner@proxmox.com \
    --to=l.wagner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal