aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/error.rs51
1 files changed, 27 insertions, 24 deletions
diff --git a/src/error.rs b/src/error.rs
index b8a078b..1b4be19 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,13 +1,12 @@
1use ::ipnetwork::IpNetworkError; 1use ipnetwork::IpNetworkError;
2use axum::http::header::ToStrError;
3use axum::http::StatusCode; 2use axum::http::StatusCode;
4use axum::response::{IntoResponse, Response}; 3use axum::response::{IntoResponse, Response};
5use axum::Json; 4use axum::Json;
6use mac_address::MacParseError; 5use mac_address::MacParseError;
7use serde_json::json; 6use serde_json::json;
8use utoipa::ToSchema;
9use std::io; 7use std::io;
10use tracing::{error, warn}; 8use tracing::{error, warn};
9use utoipa::ToSchema;
11 10
12#[derive(Debug, thiserror::Error, ToSchema)] 11#[derive(Debug, thiserror::Error, ToSchema)]
13pub enum Error { 12pub enum Error {
@@ -23,12 +22,6 @@ pub enum Error {
23 source: std::num::ParseIntError, 22 source: std::num::ParseIntError,
24 }, 23 },
25 24
26 #[error("header parse: {source}")]
27 ParseHeader {
28 #[from]
29 source: ToStrError,
30 },
31
32 #[error("string parse: {source}")] 25 #[error("string parse: {source}")]
33 IpParse { 26 IpParse {
34 #[from] 27 #[from]
@@ -55,6 +48,15 @@ impl IntoResponse for Error {
55 fn into_response(self) -> Response { 48 fn into_response(self) -> Response {
56 let (status, error_message) = match self { 49 let (status, error_message) = match self {
57 Self::Json { source } => { 50 Self::Json { source } => {
51 // !THIS REALLY SHOULD NOT HAPPEN!:
52 // Json file has to had been tampered with by an external force
53 error!("{source}");
54 (StatusCode::INTERNAL_SERVER_ERROR, "Server Error")
55 }
56 Self::ParseInt { source } => {
57 // !THIS REALLY SHOULD NOT HAPPEN!:
58 // Mac Address `&str` can't be converted to hex, which should be impossible trough
59 // `MacAddress` type-check on device registration and edit
58 error!("{source}"); 60 error!("{source}");
59 (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") 61 (StatusCode::INTERNAL_SERVER_ERROR, "Server Error")
60 } 62 }
@@ -67,25 +69,26 @@ impl IntoResponse for Error {
67 (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") 69 (StatusCode::INTERNAL_SERVER_ERROR, "Server Error")
68 } 70 }
69 } 71 }
70 Self::ParseHeader { source } => {
71 error!("{source}");
72 (StatusCode::INTERNAL_SERVER_ERROR, "Server Error")
73 }
74 Self::ParseInt { source } => {
75 error!("{source}");
76 (StatusCode::INTERNAL_SERVER_ERROR, "Server Error")
77 }
78 Self::MacParse { source } => { 72 Self::MacParse { source } => {
79 error!("{source}"); 73 warn!("{source}");
80 (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") 74 (
75 StatusCode::INTERNAL_SERVER_ERROR,
76 "The given MAC-Address couldn't be parsed",
77 )
81 } 78 }
82 Self::IpParse { source } => { 79 Self::IpParse { source } => {
83 error!("{source}"); 80 warn!("{source}");
84 (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") 81 (
85 }, 82 StatusCode::INTERNAL_SERVER_ERROR,
83 "The given IP-Address couldn't be parsed",
84 )
85 }
86 Self::NoIpOnPing => { 86 Self::NoIpOnPing => {
87 error!("Ping requested but no ip given"); 87 warn!("Ping requested but no ip given");
88 (StatusCode::BAD_REQUEST, "No Ip saved for requested device, but device started") 88 (
89 StatusCode::BAD_REQUEST,
90 "No IP saved for device, ping can't be executed. Device may be started anyway",
91 )
89 } 92 }
90 }; 93 };
91 let body = Json(json!({ 94 let body = Json(json!({