summaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/error.rs b/src/error.rs
index db2fc86..f143ee9 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,4 +1,5 @@
1use std::error::Error; 1use std::error::Error;
2use std::io;
2use axum::http::StatusCode; 3use axum::http::StatusCode;
3use axum::Json; 4use axum::Json;
4use axum::response::{IntoResponse, Response}; 5use axum::response::{IntoResponse, Response};
@@ -8,21 +9,45 @@ use crate::auth::AuthError;
8 9
9#[derive(Debug)] 10#[derive(Debug)]
10pub enum WebolError { 11pub enum WebolError {
11 Auth(AuthError),
12 Generic, 12 Generic,
13 Server(Box<dyn Error>), 13 Auth(AuthError),
14 Ping(surge_ping::SurgeError),
15 DB(sqlx::Error),
16 IpParse(<std::net::IpAddr as std::str::FromStr>::Err),
17 BufferParse(std::num::ParseIntError),
18 Broadcast(io::Error),
19 Axum(axum::Error)
14} 20}
15 21
16impl IntoResponse for WebolError { 22impl IntoResponse for WebolError {
17 fn into_response(self) -> Response { 23 fn into_response(self) -> Response {
18 let (status, error_message) = match self { 24 let (status, error_message) = match self {
19 WebolError::Auth(err) => err.get(), 25 Self::Auth(err) => err.get(),
20 WebolError::Generic => (StatusCode::INTERNAL_SERVER_ERROR, ""), 26 Self::Generic => (StatusCode::INTERNAL_SERVER_ERROR, ""),
21 WebolError::Server(err) => { 27 Self::Ping(err) => {
28 error!("Ping: {}", err.source().unwrap());
29 (StatusCode::INTERNAL_SERVER_ERROR, "Server Error")
30 },
31 Self::IpParse(err) => {
32 error!("server error: {}", err.to_string());
33 (StatusCode::INTERNAL_SERVER_ERROR, "Server Error")
34 },
35 Self::DB(err) => {
36 error!("server error: {}", err.to_string());
37 (StatusCode::INTERNAL_SERVER_ERROR, "Server Error")
38 },
39 Self::Broadcast(err) => {
40 error!("server error: {}", err.to_string());
41 (StatusCode::INTERNAL_SERVER_ERROR, "Server Error")
42 },
43 Self::BufferParse(err) => {
44 error!("server error: {}", err.to_string());
45 (StatusCode::INTERNAL_SERVER_ERROR, "Server Error")
46 },
47 Self::Axum(err) => {
22 error!("server error: {}", err.to_string()); 48 error!("server error: {}", err.to_string());
23 (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") 49 (StatusCode::INTERNAL_SERVER_ERROR, "Server Error")
24 }, 50 },
25
26 }; 51 };
27 let body = Json(json!({ 52 let body = Json(json!({
28 "error": error_message, 53 "error": error_message,