diff options
author | FxQnLr <[email protected]> | 2024-04-11 09:20:04 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2024-04-11 09:20:04 +0200 |
commit | 6b05d1a437a49db98056de7b029923e8aedf1a5a (patch) | |
tree | bc70f14cae1760e91369705273904c0de1bfbf75 /src/error.rs | |
parent | 907e5cb5bc48899b444f7fedd85af7b5974d9a2e (diff) | |
parent | 2476e182f61d209768635e8eca6e75b4acfbd007 (diff) | |
download | webol-6b05d1a437a49db98056de7b029923e8aedf1a5a.tar webol-6b05d1a437a49db98056de7b029923e8aedf1a5a.tar.gz webol-6b05d1a437a49db98056de7b029923e8aedf1a5a.zip |
Merge pull request #32 from FxQnLr/0.4.0
0.4.0
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/error.rs b/src/error.rs index 006fcdb..2d70592 100644 --- a/src/error.rs +++ b/src/error.rs | |||
@@ -7,14 +7,14 @@ use mac_address::MacParseError; | |||
7 | use serde_json::json; | 7 | use serde_json::json; |
8 | use utoipa::ToSchema; | 8 | use utoipa::ToSchema; |
9 | use std::io; | 9 | use std::io; |
10 | use tracing::error; | 10 | use tracing::{error, warn}; |
11 | 11 | ||
12 | #[derive(Debug, thiserror::Error, ToSchema)] | 12 | #[derive(Debug, thiserror::Error, ToSchema)] |
13 | pub enum Error { | 13 | pub enum Error { |
14 | #[error("db: {source}")] | 14 | #[error("json: {source}")] |
15 | Db { | 15 | Json { |
16 | #[from] | 16 | #[from] |
17 | source: sqlx::Error, | 17 | source: serde_json::Error, |
18 | }, | 18 | }, |
19 | 19 | ||
20 | #[error("buffer parse: {source}")] | 20 | #[error("buffer parse: {source}")] |
@@ -50,15 +50,20 @@ pub enum Error { | |||
50 | 50 | ||
51 | impl IntoResponse for Error { | 51 | impl IntoResponse for Error { |
52 | fn into_response(self) -> Response { | 52 | fn into_response(self) -> Response { |
53 | error!("{}", self.to_string()); | 53 | // error!("{}", self.to_string()); |
54 | let (status, error_message) = match self { | 54 | let (status, error_message) = match self { |
55 | Self::Db { source } => { | 55 | Self::Json { source } => { |
56 | error!("{source}"); | 56 | error!("{source}"); |
57 | (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") | 57 | (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") |
58 | } | 58 | } |
59 | Self::Io { source } => { | 59 | Self::Io { source } => { |
60 | error!("{source}"); | 60 | if source.kind() == io::ErrorKind::NotFound { |
61 | (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") | 61 | warn!("unknown device requested"); |
62 | (StatusCode::NOT_FOUND, "Requested device not found") | ||
63 | } else { | ||
64 | error!("{source}"); | ||
65 | (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") | ||
66 | } | ||
62 | } | 67 | } |
63 | Self::ParseHeader { source } => { | 68 | Self::ParseHeader { source } => { |
64 | error!("{source}"); | 69 | error!("{source}"); |