From 2f9f18b80a9e2134f674f345e48a5f21de5efadd Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Sun, 18 Feb 2024 21:16:46 +0100 Subject: Refactor stuff. Use Postgres Types --- src/error.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/error.rs') diff --git a/src/error.rs b/src/error.rs index 63b214e..66a61f4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -2,6 +2,8 @@ use axum::http::header::ToStrError; use axum::http::StatusCode; use axum::response::{IntoResponse, Response}; use axum::Json; +use ::ipnetwork::IpNetworkError; +use mac_address::MacParseError; use serde_json::json; use std::io; use tracing::error; @@ -29,6 +31,18 @@ pub enum Error { source: ToStrError, }, + #[error("string parse: {source}")] + IpParse { + #[from] + source: IpNetworkError, + }, + + #[error("mac parse: {source}")] + MacParse { + #[from] + source: MacParseError, + }, + #[error("io: {source}")] Io { #[from] @@ -57,6 +71,14 @@ impl IntoResponse for Error { error!("{source}"); (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") } + Self::MacParse { source } => { + error!("{source}"); + (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") + } + Self::IpParse { source } => { + error!("{source}"); + (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") + } }; let body = Json(json!({ "error": error_message, -- cgit v1.2.3